|
-
May 18th, 2001, 10:25 AM
#1
Thread Starter
New Member
RegQueryValueEx
Part of the program I'm writing accesses a registry key on a remote PC. Here's the code I’m using, what’s wrong with it?
----------------------------------------------------------------------
Declarations
----------------------------------------------------------------------
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 RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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
----------------------------------------------------------------------
Code
----------------------------------------------------------------------
Public Function GetDomain(MachineName) As String
MachPatch = "\\" & MachineName
RemoteRegConnection = RegConnectRegistry(MachPatch, HKEY_LOCAL_MACHINE, RemoteLocalMachine)
If RemoteRegConnection <> ERROR_SUCCESS Then
GetDomain = "Fail"
Exit Function
End If
KeyPath = RegOpenKeyEx(RemoteLocalMachine, "Software\Microsoft\Windows NT\CurrentVersion\Winlogon", 0, KEY_READ, DomainKey)
If KeyPath <> ERROR_SUCCESS Then
GetDomain = "Fail"
Exit Function
End If
QueryKey = RegQueryValueEx(DomainKey, "DefaultDomainName", 0, REG_SZ, PrimaryDomain, 8)
If QueryKey <> ERROR_SUCCESS Then
GetDomain = "Fail"
Exit Function
End If
CloseKey = RegCloseKey(DomainKey)
CloseKey = RegCloseKey(RemoteLocalMachine)
GetDomain = PrimaryDomain
End Function
----------------------------------------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|