REGISTRO DO WINDOWS

USUARIO.EXCLUIDOS 18/11/2004 20:43:25
#51012
Alguém saberia me dizer como fazer para perguntar para o Windows em qual local está salvo o WinWord.exe, o Excel.Exe, pois meu programa abre esses dois programas (simplesmente com atalho para o usuário), mas como sei que o usuário pode mudar o local padrão, gostaria de perguntar para o Windows (registro) onde eles est!ao
USUARIO.EXCLUIDOS 19/11/2004 04:08:05
#51032
Resposta escolhida
Para o Word:
Insira no form um command com o nome cmd_Le_Registro
cole o código no form:
  
Option Explicit

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String

Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = 1 Then
strBuf = String(lDataBufSize, Chr$(0))
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = 1 Then
Dim strData As Integer
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If

End Function

Function GetString(hKey As Long, strPath As String, strValue As String)

Dim RET
RegOpenKey hKey, strPath, RET
GetString = RegQueryStringValue(RET, strValue)
RegCloseKey RET

End Function

Private Sub cmd_Le_Registro_Click()

Dim RET As String
RET = GetString(&H80000002, "Software\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe", "Path")
If RET = "" Then MsgBox "Valor não encontrado!", vbExclamation + vbOKOnly, App.Title: Exit Sub
MsgBox RET & "WINWORD.EXE", vbOKOnly + vbInformation, App.Title

End Sub
USUARIO.EXCLUIDOS 19/11/2004 04:12:23
#51033
Para o Excel:
Adicione no projeto anterior um novo command (cmd_Le_RegistroExcel) e cole nele:
 
Private Sub cmd_Le_RegistroExcel_Click()

Dim RET As String
RET = GetString(&H80000002, "Software\Microsoft\Windows\CurrentVersion\App Paths\Excel.exe", "Path")
If RET = "" Then MsgBox "Valor não encontrado!", vbExclamation + vbOKOnly, App.Title: Exit Sub
MsgBox RET & "EXCEL.EXE", vbOKOnly + vbInformation, App.Title

End Sub


Boa noite!
Tópico encerrado , respostas não são mais permitidas