zu1:
Declare Function RegOpenKeyExA Lib "advapi32" Alias "RegOpenKeyExA" (Byval HKEY As Long,Byval lpszSubKey As String,Byval dwreserved As Integer,Byval samDesired As Long, keyresult As Long) As Long
Declare Function RegQueryValueExA Lib "advapi32" Alias "RegQueryValueExA" (Byval HKEY As Long,Byval lpszValueName As String,Byval dwreserved As Integer, lpdwtype As Long, Byval lpData As String, readbytes As Long) As Long
Declare Function RegCloseKey Lib "advapi32" Alias "RegCloseKey" (Byval HKEY As Long) As Long
Dim Test As String
Sub Click(Source As Button)
app$ = Inputbox("Enter the name of an .EXE file you want to locate.", "Name of App", "NOTES.EXE")
AppPath$ = LocatePath(app$)
'----display the results
If AppPath$ = Test Then
Msgbox ApplicationName & " not found."
Else
Msgbox AppPath$
End If
End Sub
Function LocatePath(ApplicationName As String)
Dim happkey As Long
Dim HKEY_LOCAL_MACHINE As Long
Dim KEY_READ As Long
Dim HKEY_CURRENT_USER As Long
Dim ValueType As Long
Dim ReturnedKeyContents As String * 255
Dim readbytes As Long
ReturnedKeycontents$=String$(255,Chr$(32)) ' sets up the returned key variable, C likes to know how long it's strings might be
Test = ReturnedKeycontents$ ' string used to test results of lookup; represents a blank return
'----the base keys of the registry. we will be drilling into HKEY_LOCAL_MACHINE in this instance
HKEY_LOCAL_MACHINE= &H80000002
HKEY_CURRENT_USER= &H80000001
'----keys used by C function calls, used to navigate registry
KEY_QUERY_VALUE=1
KEY_ENUMERATE_SUBKEYS=8
KEY_NOTIFY=16
KEY_READ=KEY_QUERY_VALUE Or KEY_ENUMERATE_SUBKEYS Or KEY_NOTIFY
BaseName$ = "Software\Microsoft\Windows\CurrentVersion\App Paths\" ' this is the default part of the key
KeyName$= BaseName$ + ApplicationName ' this adds the user-entered exe to the basename, creating the key
ValueName$ = "" ' a null or empty string represents the default value
lstat=RegOpenKeyExA(HKEY_LOCAL_MACHINE,KeyName$,0,KEY_READ,happkey) ' get a handle on the key, values are passed by refrence
ReadBytes=255
lstat=RegQueryValueExA(happkey,ValueName$,0,valueType, ReturnedKeyContents$,ReadBytes) ' get the value of the desired value
regclosekey(happkey) ' release the handle of the key
Test = Left$(Test, ReadBytes-1)
LocatePath = Left$(ReturnedKeyContents$,ReadBytes-1) ' format and return the results
End Function