Sonreir Posted March 2, 2004 Posted March 2, 2004 I understand the use of the Shell / Process.Start function, but what if I don't 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. Quote
*Gurus* Derek Stone Posted March 2, 2004 *Gurus* Posted March 2, 2004 Use the Microsoft.Win32.Registry class to query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\". Quote Posting Guidelines
Sonreir Posted March 2, 2004 Author Posted March 2, 2004 Forgive the onslaught of questions, but I'm a novice. I've got little experience with the registry and I'm not sure about the snytax of the Registry class. Microsoft.Win32.Registry.LocalMachine.ToString returns the string: HKEY_LOCAL_MACHINE [0x80000002] Anyway, I'm pretty sure that bit is irrelevant. How do I use Microsoft.Win32.Registry to query? What's the proper syntax and what data type will it return? I'm 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 Quote
Leaders dynamic_sysop Posted March 2, 2004 Leaders Posted March 2, 2004 here's a quick example , add a listbox and a button to a form , then put this in the button_click event ... 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 there's no path either here. appPath += "\" & strPath ListBox1.Items.Add(appPath) End If End If Next Quote
Recommended Posts