Pages

Monday, March 19, 2012

How to get the location of software installed in server machine.


You can check the Registry Key for the Software installed location. You can do this by your VB code and run the exe you want in that location.
I will explain you this with a small example.
Imports Microsoft.Win32
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Enter the Software name you are searching for like SOFTWARE\Microsoft\Microsoft SQL Server
        Using sqlServerKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server")
            For Each subKeyName As String In sqlServerKey.GetSubKeyNames()
                ' Get the subFolder
                If subKeyName.StartsWith("100") Then
                    Using instanceKey As RegistryKey = sqlServerKey.OpenSubKey(subKeyName)
                        ' Get the subFolder
                        Dim path As String = instanceKey.OpenSubKey("DTS").OpenSubKey("Setup").GetValue("SQLPath")
                        ' Enter the exe name you wants.
                        path = path + "Binn\DTExec.exe"
                        MessageBox.Show(path)
                    End Using
                End If
            Next
        End Using
    End Sub
End Class

No comments: