Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find an application-path in the registry

Status
Not open for further replies.

wrchto

IS-IT--Management
Jan 3, 2001
14
AT
Hi!

I need to find the path of an application (excel.exe) in the registry because on each client it could be another path. So I need the code for searching in the registry.
If I know the correct path, I can start the application with the Shell-Command.

Thomas
 
Try this code. Obviously you will need to know the exact area of the Registry to read.

Dim lReturn As Long
Dim lLen As Long
Dim lType As Long
Const SubKey_Name As String = "Control Panel\Mouse"
Const SubKey_Value As String = "MouseSpeed"
Dim mhKeyHandle As Long
Dim msKeyValue As String

lReturn = RegOpenKeyEx(HKEY_CURRENT_USER, SubKey_Name, 0, KEY_READ, mhKeyHandle)
lLen = 200
lType = REG_SZ
msKeyValue = String(lLen, 0)
lReturn = RegQueryValueExString(mhKeyHandle, SubKey_Value, 0&, lType, msKeyValue, lLen)
msKeyValue = Left$(msKeyValue, lLen)
lReturn = RegCloseKey(mhKeyHandle)

 
This will return the full path to EXCEL.EXE without messing with the registry:
[tt]
Private Const MAX_FILENAME_LEN = 260
Private Declare Function FindExecutable _
Lib "shell32.dll" _
Alias "FindExecutableA" (ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long

Private Sub Command1_Click()
FileName$ = "Test This App.xls"
Open FileName$ For Binary As #1
Close #1
Tmp$ = String(MAX_FILENAME_LEN, 32)
RetVal = FindExecutable(FileName$, vbNullString, Tmp$)
If RetVal > 32 Then
Tmp$ = Replace(Tmp$, Chr$(0), " ")
If InStr(Tmp$, Chr$(34)) > 0 Then
Tmp$ = Left$(Tmp$, InStr(Tmp$, Chr$(34)) - 1)
End If
MsgBox Trim(Tmp$)
Else
MsgBox "No EXE associated with that file extention."
End If
End Sub
[/tt]

BTW: You could start Excel without knowing the application path if you just opened any-old XLS with [tt]ShellExecute[/tt].
VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top