Results 1 to 12 of 12

Thread: Remote Registry

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64

    Remote Registry

    Anyone know how to use the RegConnectRegistry API to connect to a registry across the network?

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    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]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64
    Do I just replace the RegConnectRegistry(" & vbNullChar... with RegConnectRegistry([compname] & vbNullChar... or do I need to do some additional editing?

  4. #4
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    your correct!
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64
    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.

  6. #6
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    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.

  7. #7
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    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]

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64
    The one I've been trying to connect to is HKEY_LOCAL_MACHINE but I can't get it to work.

  9. #9
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64
    That's what I was thinking. THey Might have connecting to a remote registry blocked.

  11. #11
    Member
    Join Date
    Sep 2000
    Posts
    39
    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.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64
    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
  •  



Click Here to Expand Forum to Full Width