CHAVE DE REGISTRO
Pessoal como faço para verificar se uma chave de registro existe utilizando o VB6?
Obs.: Já tenho o código para ler, excluir e incluir
Obs.: Já tenho o código para ler, excluir e incluir
Private Declare Function RegOpenKeyEx Lib [Ô]advapi32.dll[Ô] Alias [Ô]RegOpenKeyExA[Ô] _
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib [Ô]advapi32.dll[Ô] (ByVal hKey As Long) As _
Long
Const KEY_READ = &H20019
Const HKEY_CURRENT_USER = &H80000001
[ô]~~> Return True if a Registry key exists
Function CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As Boolean
Dim handle As Long
[ô]~~> Try to open the key
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then
[ô]~~> The key exists
CheckRegistryKey = True
[ô]~~> Close it before exiting
RegCloseKey handle
End If
End Function
Private Sub Command1_Click()
[ô]~~> Visual Basic, by default using GetSetting and SaveSetting allows reading and
[ô]~~> writing only to the VB and VBA Programs key under HKEY_Current_User\Software.
Dim strSubKey As String
strSubKey = [Ô]Software\[Ô] & Trim(Text1.Text)
[ô]~~> will return True if it exists
MsgBox CheckRegistryKey(HKEY_CURRENT_USER, strSubKey)
End Sub
[txt-color=#e80000]Não esqueça de pontuar [/txt-color]
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib [Ô]advapi32.dll[Ô] (ByVal hKey As Long) As _
Long
Const KEY_READ = &H20019
Const HKEY_CURRENT_USER = &H80000001
[ô]~~> Return True if a Registry key exists
Function CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As Boolean
Dim handle As Long
[ô]~~> Try to open the key
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then
[ô]~~> The key exists
CheckRegistryKey = True
[ô]~~> Close it before exiting
RegCloseKey handle
End If
End Function
Private Sub Command1_Click()
[ô]~~> Visual Basic, by default using GetSetting and SaveSetting allows reading and
[ô]~~> writing only to the VB and VBA Programs key under HKEY_Current_User\Software.
Dim strSubKey As String
strSubKey = [Ô]Software\[Ô] & Trim(Text1.Text)
[ô]~~> will return True if it exists
MsgBox CheckRegistryKey(HKEY_CURRENT_USER, strSubKey)
End Sub
[txt-color=#e80000]Não esqueça de pontuar [/txt-color]
Maravilha!
Funcionou perfeitamente.
Funcionou perfeitamente.
Tópico encerrado , respostas não são mais permitidas