Wednesday, March 7, 2012

Msde installation

hi

I am trying to install msde through my .net application.Before that i wnat to check if that instance already exist or not.Can any tell me how i can do that

regards
Dhanya

Try navigating through all the keys under HKEY_CLASSES_ROOT\Installer\Products and check for the key ProductName which contains text "Microsoft SQL Server Desktop Engine". If you can find one, it means that the MSDE is already installed.

And if you are looking for a code snippet then the following may help you

C# SAMPLE
public static bool IsMsdeInstalled()
{
Microsoft.Win32.RegistryKey Key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Installer").OpenSubKey("Products");
foreach (string _key in Key.GetSubKeyNames())
{
string value = Key.OpenSubKey(_key).GetValue("ProductName").ToString();
if(value.Contains("Microsoft SQL Server Desktop Engine"))
return true;
}
return false;
}

VB.NET SAMPLE

Public Shared Function IsMsdeInstalled() As Boolean
Dim Key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Installer").OpenSubKey("Products")
For Each _key As String In Key.GetSubKeyNames()
Dim value As String = Key.OpenSubKey(_key).GetValue("ProductName").ToString()
If value.Contains("Microsoft SQL Server Desktop Engine") Then
Return True
End If
Next
Return False
End Function

No comments:

Post a Comment