[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

how to edit registry on remote machine without being logged on remote machine

I'm trying to change some settings on a remote machine, but it doesn't work unless I(me) am logged on that machine!?!?

I get no error running the sub

Here is a part of my code that changes the startpage in IE:

'Update startpage
Private Sub Command3_Click()
    On Error Resume Next
    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002
   
    strComputer = Form1.Text1.Text
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
             strComputer & "\root\default:stdRegProv")
    strKeyPath = "Software\Microsoft\Internet Explorer\Main"
    strValueName = "Start Page"
    oReg.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
   
    If Err Then
    Form1.Text2.Text = "Machine is turned off, or do not exist in the domain"
   
    Else
        strKeyPath = "Software\Microsoft\Internet Explorer\Main"
        strValueName = "Start Page"
        strValue = "http://intranet"
        oReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
       
 Form1.Text2.Text = "Startpage on " & strComputer & " has been changed to " & strValue
End If
End Sub
0
aslandk
Asked:
aslandk
  • 4
  • 2
1 Solution
 
_ys_Commented:
By defintion HKEY_CURRENT_USER is only available when someone logs into the physical machine. (Technically it's per winstation, but that just over complicates the issue).

The WMI service is likely configured to run as the LocalSystem, and so, again, doesn't have access to HKEY_CURRENT_USER by defition.

Configuring the WMI service to run as a specific user should allow access to a HKEY_CURRENT_USER hive.

From what you're trying to achieve though, walking the HKEY_USERS hive, and setting this registry value for all known users (including .DEFAULT) sounds like a better thing to do.
0
 
aslandkAuthor Commented:
could you give me and example of how to "From what you're trying to achieve though, walking the HKEY_USERS hive, and setting this registry value for all known users (including .DEFAULT) sounds like a better thing to do."

Thanks:)
0
 
_ys_Commented:
This will set it for each individual user, and HKEY_LOCAL_MACHINE (effectively an all users option).

---------x----------
'Update startpage
Private Sub Command3_Click()
    On Error Resume Next
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const HKEY_USERS = &H80000003
   
    strComputer = Form1.Text1.Text
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
             strComputer & "\root\default:stdRegProv")
    strKeyPath = "Software\Microsoft\Internet Explorer\Main"
    strValueName = "Start Page"
    strValue = "http://intranet"

' Original all users option
    oReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue

' Change it for each known user
    oReg.EnumKey HKEY_USERS, "", arrSubKeys

    For Each strSubKey In arrSubKeys
        oReg.SetStringValue HKEY_USERS, strSubKey & strKeyPath, strValueName, strValue
    Next
       
 Form1.Text2.Text = "Startpage on " & strComputer & " has been changed to " & strValue
End If
End Sub
---------x----------

By avoiding HKEY_CURRENT_USER you don't can ignore everything else I suggested.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
_ys_Commented:
VB is not my strongest language by far, so you may have to tweak the above.
0
 
aslandkAuthor Commented:
hi again

i've tried several things, but it doesn't work on remote PCs

it seems it goes in the wrong level - one level too deep.

here is my code(look at the ----------- part) :


Const HKEY_USERS = &H80000003
    strCmd = 'Form1.Text1.Text
    strKeyPath = "\Software\Microsoft\Internet Explorer\Main"
    strValueName = "Start Page"
    strValue = "http://intranet"
   
    If strCmd = "" Then
        Set objWbem = GetObject("winmgmts:")
        Set objRegistry = GetObject("winmgmts:\root\default:StdRegProv")
    Else
        Set objWbem = GetObject("winmgmts:\\" & strCmd)
        Set objRegistry = GetObject("winmgmts:\\" & strCmd & "\root\default:StdRegProv")
    End If
    lngRtn = objRegistry.EnumKey(HKEY_USERS, "", arrRegKeys)
    If lngRtn = 0 Then
        For Each strKey In arrRegKeys
-------------------------------------------------------------------------------------------------------------------------------------
here is the problem, if i print out strkey, i don't get "S-1-5-21-blabla", but "software", "control panel" and "etc". witch is subkeys to the "S-1-5-21-blabla" keys!! why does it do that???
-------------------------------------------------------------------------------------------------------------------------------------
            If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
                ' Do Nothing
            Else
                If InStr(strKey, "S-1-5-21-") Then
                    Set objsid = objWbem.Get("Win32_SID.SID='" & strKey & "'")
                    MsgBox "computer: " & strCmd & " path: " & strKey & strKeyPath & " key: " & strValueName & " value: " & strValue
                    If Not getreginfo(0, strCmd, strKey & strKeyPath, strValueName, strValue) Then
                        Call setreginfo(strCmd, strKey & strKeyPath, strValueName, strValue)
                        If getreginfo(0, strCmd, strKey & strKeyPath, strValueName, strValue) Then
                            found = True
                            edited = True
                            MsgBox "edited"
                        Else
                            MsgBox "error! ending!"
                            Exit For
                        End If
                    Else
                        found = True
                        MsgBox "found"
                    End If
                End If
            End If
        Next
    End If
End Sub
0
 
_ys_Commented:
Would you be running Win2k with SP4 by any chance ...

Found this related issue:
http://www.talkaboutsoftware.com/group/microsoft.public.win2000.registry/messages/26976.html

Also, I noted that you've left out the remote computer name in the above code. Intentional or just trying to get it working locally first.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now