|
-
Apr 26th, 2001, 01:09 PM
#1
Thread Starter
Lively Member
Remote Registry
Anyone know how to use the RegConnectRegistry API to connect to a registry across the network?
-
Apr 26th, 2001, 03:14 PM
#2
Fanatic Member
i do somewhat. i tossed together this example a while back, but haven't been able to test it on anthing other than my local machine. give it a try:
Code:
'Name: Network Registry Functions
'Description: Access
' Network Registry
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Const REG_SZ = 1
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
'Create a New project And add this code To Form1
Private Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const LANG_NEUTRAL = &H0
Private Const SUBLANG_DEFAULT = &H1
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Private Sub ShowError(errnum As Long)
Dim Buffer As String
'Create a String buffer
Buffer = Space(200)
'Set the Error number
'Format the message String
FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, errnum, LANG_NEUTRAL, Buffer, 200, ByVal 0&
'Show the message
MsgBox Buffer
End Sub
Public Sub SetKeys()
Dim sSave As String
Dim hKey As Long
Dim hNetKey As Long
Dim Cnt As Integer
Dim retval As Long
retval = RegConnectRegistry("" & vbNullChar, HKEY_LOCAL_MACHINE, hNetKey)
ShowError (retval)
retval = RegOpenKey(hNetKey, "\Software\Microsoft\Windows\CurrentVersion\RunServices\", hKey)
ShowError (retval)
retval = RegSetValueEx(hKey, App.EXEName, 0, REG_SZ, ByVal App.Path, Len(App.Path))
ShowError retval
RegCloseKey hKey
RegCloseKey hNetKey
End Sub
Private Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
'Search the first chr$(0)
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
Right now it's configured for setting up remote services, but you can modify it, the concept is there
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Apr 29th, 2001, 01:52 PM
#3
Thread Starter
Lively Member
Do I just replace the RegConnectRegistry(" & vbNullChar... with RegConnectRegistry([compname] & vbNullChar... or do I need to do some additional editing?
-
Apr 29th, 2001, 02:19 PM
#4
Fanatic Member
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
May 1st, 2001, 08:38 AM
#5
Thread Starter
Lively Member
I am still unable to connect to the remote registry. When I type in the name of my computer, it works regardless of capitalization or whether it's in the form of \\[compname] or not. I can't figure it out.
-
May 1st, 2001, 09:01 AM
#6
Addicted Member
First you need "Microsoft Remote Registry Service" installed on the server.
You cannot Access HKEY_CLASSES_ROOT or HKEY_CURRENT_USER as a key.
you can access HKEY_LOCAL_MACHINE and HKEY_USERS
for Windows NT/2K HKEY_PERFORMANCE_DATA is also avaible
and for 9x/ME HKEY_CURRENT_CONFIG is avaible.
I'm not sure if it is compatable with VB thou as the buffer requires a Pointer which VB cannot handle.
-
May 1st, 2001, 07:03 PM
#7
Fanatic Member
vb does automatic pointers, you can use them, it's just tricky
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
May 2nd, 2001, 10:41 AM
#8
Thread Starter
Lively Member
The one I've been trying to connect to is HKEY_LOCAL_MACHINE but I can't get it to work.
-
May 2nd, 2001, 12:35 PM
#9
Black Cat
Could it be a permissions issue?
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
May 7th, 2001, 12:32 PM
#10
Thread Starter
Lively Member
That's what I was thinking. THey Might have connecting to a remote registry blocked.
-
May 7th, 2001, 03:37 PM
#11
Member
Why don't you try using Regedit.exe first to connect to the remote system first. If you are succesfull connecting then it's not the permissions issue, but rather problem in your code.
-
May 8th, 2001, 12:12 PM
#12
Thread Starter
Lively Member
I tried using Regedit to connect to another computer, and it won't let me. It says "Unable to connect to [compname]. Make sure the computer is on the network, has remote administration enabled, and that both computers are running the remote registry service." What Remote Registry Service?
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
|