Help w/ Shell function please.

Sonreir

Member
Joined
Mar 2, 2004
Messages
5
Location
Hampshire, UK
I understand the use of the Shell / Process.Start function, but what if I dont know the path (only the name) of the program I am trying to start? Is there another function that can perform a search and return the path? Thanks in advance.
 
Use the Microsoft.Win32.Registry class to query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\".
 
Forgive the onslaught of questions, but Im a novice. Ive got little experience with the registry and Im not sure about the snytax of the Registry class.

Microsoft.Win32.Registry.LocalMachine.ToString returns the string:
HKEY_LOCAL_MACHINE [0x80000002]

Anyway, Im pretty sure that bit is irrelevant. How do I use Microsoft.Win32.Registry to query? Whats the proper syntax and what data type will it return? Im assuming that "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" is some sort of arguement.

Any working examples I can test and practice with?

Thanks again.

-Matt
 
heres a quick example , add a listbox and a button to a form , then put this in the button_click event ...
Code:
        Dim rKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths", False)
        Dim itemKey As Microsoft.Win32.RegistryKey

        Dim strItems As String() = rKey.GetSubKeyNames /// get all the application name keys in the app paths section.
        Dim strPath As String
        For Each strPath In strItems
            itemKey = rKey.OpenSubKey(strPath)
            Dim appPath As String = Convert.ToString(itemKey.GetValue(""))  /// default = ""
            If Not appPath.Length = 0 Then
                ListBox1.Items.Add(appPath) /// this is a valid exe path for an exe ( all registered exes )  thats installed on your pc
            Else
                appPath = Convert.ToString(itemKey.GetValue("path"))  /// some files have a folder path key , but no default value.
                If Not appPath.Length = 0 Then /// sometimes theres no path either here.
                    appPath += "\" & strPath
                    ListBox1.Items.Add(appPath)
                End If
            End If
        Next
 
Back
Top