How to drop Primary Key of a Table using MSSQL

To drop Primary Key of a Table using MSSQL you can use the snippet below.

Sample MSSQL

ALTER TABLE tblTest
DROP CONSTRAINT PK_tblTest
GO

Please rate this snippet

How to get Windows Product Name in C# and VB.NET

To get Windows Product Name in C# and VB.NET you can use the following snippet.

Sample C#

public static string GetWindowsProdutName()
{
	var name = (new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>().Select(x => x.GetPropertyValue("Caption"))).First();
	return name != null ? name.ToString() : "Unknown";
}

Sample VB.NET

Public Shared Function GetWindowsProdutName() As String
	Dim name = (New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").[Get]().OfType(Of ManagementObject)().[Select](Function(x) x.GetPropertyValue("Caption"))).First()
	Return If(name IsNot Nothing, name.ToString(), "Unknown")
End Function

Tipp: To use ManagementObjectSearcher you need to set a Reference to System.Management.

Please rate this snippet

How to list all Databases in MSSQL

To list all Databases in MSSQL you can use the following snippet.

Sample MSSQL

SELECT name FROM sys.databases

SQL Server Version newer than MS SQL 2000 also support these StoredProcedures.

EXEC sp_databases

or

EXEC sp_helpdb

Please rate this snippet

How to TRIM a string in MSSQL

To TRIM a string in MSSQL you can use the following Userdefinedfunction Snippet.

Sample MSSQL

CREATE FUNCTION dbo.TRIM(@inputString VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@inputString))
END

Please rate this snippet

How to reset the windows audio mixer in Batch

To reset the windows audio mixer in Batch you can use the following snippet.
This snippet will set all volume levels equal. If you know a simpler way to reset the audio mixer, without setting all volume levels manually please let us know.

Sample Batch

@ECHO OFF
ECHO Resetting Volume Mixer Settings!
NET STOP Audiosrv
NET STOP AudioEndpointBuilder
REG DELETE "HKCU\Software\Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore" /F
REG ADD "HKCU\Software\Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore"
NET START Audiosrv

Please rate this snippet

How to use the Microsoft Speech API in VBScript

To use the Microsoft Speech API in VBScript you can use the following snippet.

Sample VBScript

dim sTextToSpeech 
sTextToSpeech = "HELLO WORLD!"
set ObjVoice = CreateObject("SAPI.SpVoice") 
ObjVoice.Speak sTextToSpeech 

Please rate this snippet

How to start a process and wait for exit in Powershell

To start a application and wait for exit in Powershell you can use the following snippet.

Sample Powershell

start-process -filepath "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" -Wait -NoNewWindow -argumentlist '-args'

for more informations take a look at the MSDN Start-Process

Please rate this snippet