Jump to content

Remote Registry Editing


Recommended Posts

I am looking for a way to make changes to HK_Current_User on a remote pc. When I open regedit and connect to the remote computer, it does not show me HK_Current_User (I know it shouldnt), rather I have to connect to HK_Users\UserSerialnumber\software\microsoft and so on. Unfortunatly the User Serial Number changes from pc to pc. Is there a way that I can detect what the serial for the currenly loggeg on user is? I know when you connect with poledit, it gives you a choice of the users that exists on that specific pc.

Any information would be greatly valued.

Link to comment
Share on other sites

  • Moderators

Maybe this will help. It creates a listview of all the usernames and thier SID from the computer you specify.

#include <GUIConstants.au3>
#include <GuiListView.au3>

Dim $SID
$Computer = InputBox("Computer Name", "Please enter the computer name you wish to connect to:")

$SID = _UserSID("", $Computer); Create an array with all username from a machine

; == GUI generated with Koda ==
$Form1 = GUICreate("Username\SID List", 500, 300, 192, 125, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))
$List1 = GUICtrlCreateListView("Username|SID", 5, 5, 490, 290, BitOR($LVS_NOSORTHEADER, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))

;Adding username to listview
For $x = 1 To $SID[0][0]
    GUICtrlCreateListViewItem($SID[0][$x] & "|" & $SID[1][$x], $List1)
Next
_GUICtrlListViewSetColumnWidth ($List1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListViewSetColumnWidth ($List1, 1, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Exit

;===============================================================================
; Function Name: _UserSID()
;
; Description: Return a 2 dimensional array first username second SID.
;
; Syntax: _UserSID ( [$s_UserName, $s_RemoteComputer] )
;
; Parameter(s): $s_UserName = Username to get SID.
; $s_RemoteComputer = ComputerName on the network
;
; Requirement(s): External: = None.
; Internal: = None.
;
; Return Value(s): On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0.
; On Failure: = Returns "" and sets @error to 1.
;
; Author(s): Dan Colón
;
; Note(s):
;
; Example(s):
; _UserSID("DColon") it will return DColon SID
; _UserSID() it will return every user SID
;===============================================================================

Func _UserSID($s_UserName = "All", $s_RemoteComputer = '')
    If $s_UserName = '' Then $s_UserName = 'All'
    If $s_RemoteComputer <> '' Then
        If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then
            $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
        EndIf
    EndIf
    
    Local $line, $var, $ProfilePath, $i = 1
    Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
    Local Const $regkeyval1 = "ProfilesDirectory"
    Local Const $regkeyval2 = "ProfileImagePath"
    
    $ProfilePath = RegRead($regkey, $regkeyval1)
    While 1
        $line = RegEnumKey($regkey, $i)
        $var = RegRead($regkey & $line, $regkeyval2)
        If @error = 1 Or @error = -1 Then ExitLoop
        If $s_UserName == "All" Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        EndIf
        $i = $i + 1
    WEnd
    If Not IsDeclared("aArray") Then
        SetError(1)
        Return ("")
    Else
        SetError(0)
        Return ($aArray)
    EndIf
EndFunc ;==>_UserSID
Edited by big_daddy
Link to comment
Share on other sites

I trying to change this script so that I can read a selected entry from the sid section and then use it to make the registry change. Unfortunatly I dont use listview much and dont know what the command is to read the information that I need. Can you help me with that information?

Link to comment
Share on other sites

Ok , here we go

#include <GUIConstants.au3>
#include <GuiListView.au3>

Dim $SID
$Computer = InputBox("Computer Name", "Please enter the computer name you wish to connect to:")

$SID = _UserSID("", $Computer); Create an array with all username from a machine

; == GUI generated with Koda ==
$Form1 = GUICreate("Outlook Printer Patch", 500, 340, 192, 125, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))
$List1 = GUICtrlCreateListView("Username|SID", 5, 5, 490, 290, BitOR($LVS_NOSORTHEADER, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))
$Deploybutton = GUICtrlCreateButton("Deploy Patch",395,300,100,35)
$Exitbutton = GUICtrlCreateButton("Exit",5,300,100,35)
;Adding username to listview
For $x = 1 To $SID[0][0]
    GUICtrlCreateListViewItem($SID[0][$x] & "|" & $SID[1][$x], $List1)
Next
_GUICtrlListViewSetColumnWidth ($List1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListViewSetColumnWidth ($List1, 1, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Deploybutton
            If _GUICtrlListViewGetSelectedCount($List1) = 0 Then
                MsgBox(0,"Error","Please select a user")
                Else
                    $selectedSID = "";whatever command to find out what text is selected.
                    RegWrite("HKEY_USERS\" &$selectedSID &"\Software\Microsoft\Office\8.0\Outlook\Printing","Print Settings File","reg_sz","C:\OutlPrnt")
            
            EndIf
        Case $msg = $Exitbutton
            Exit
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Exit

;===============================================================================
; Function Name: _UserSID()
;
; Description: Return a 2 dimensional array first username second SID.
;
; Syntax: _UserSID ( [$s_UserName, $s_RemoteComputer] )
;
; Parameter(s): $s_UserName = Username to get SID.
; $s_RemoteComputer = ComputerName on the network
;
; Requirement(s): External: = None.
; Internal: = None.
;
; Return Value(s): On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0.
; On Failure: = Returns "" and sets @error to 1.
;
; Author(s): Dan Colón
;
; Note(s):
;
; Example(s):
; _UserSID("DColon") it will return DColon SID
; _UserSID() it will return every user SID
;===============================================================================

Func _UserSID($s_UserName = "All", $s_RemoteComputer = '')
    If $s_UserName = '' Then $s_UserName = 'All'
    If $s_RemoteComputer <> '' Then
        If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then
            $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
        EndIf
    EndIf
    
    Local $line, $var, $ProfilePath, $i = 1
    Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
    Local Const $regkeyval1 = "ProfilesDirectory"
    Local Const $regkeyval2 = "ProfileImagePath"
    
    $ProfilePath = RegRead($regkey, $regkeyval1)
    While 1
        $line = RegEnumKey($regkey, $i)
        $var = RegRead($regkey & $line, $regkeyval2)
        If @error = 1 Or @error = -1 Then ExitLoop
        If $s_UserName == "All" Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        EndIf
        $i = $i + 1
    WEnd
    If Not IsDeclared("aArray") Then
        SetError(1)
        Return ("")
    Else
        SetError(0)
        Return ($aArray)
    EndIf
EndFunc;==>_UserSID

I belive the only section I still need is located within the while 1 loop.

Link to comment
Share on other sites

  • Moderators

I haven't tested it, but I think this will work.

#include <GUIConstants.au3>
#include <GuiListView.au3>

Dim $SID
$Computer = InputBox("Computer Name", "Please enter the computer name you wish to connect to:")

$SID = _UserSID("", $Computer); Create an array with all username from a machine

; == GUI generated with Koda ==
$Form1 = GUICreate("Outlook Printer Patch", 500, 340, 192, 125, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))
$List1 = GUICtrlCreateListView("Username|SID", 5, 5, 490, 290, BitOR($LVS_NOSORTHEADER, $LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
$Deploybutton = GUICtrlCreateButton("Deploy Patch", 395, 300, 100, 35)
$Exitbutton = GUICtrlCreateButton("Exit", 5, 300, 100, 35)
;Adding username to listview
For $x = 1 To $SID[0][0]
    GUICtrlCreateListViewItem($SID[0][$x] & "|" & $SID[1][$x], $List1)
Next
_GUICtrlListViewSetColumnWidth ($List1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListViewSetColumnWidth ($List1, 1, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Deploybutton
            $count = _GUICtrlListViewGetSelectedCount ($List1)
            If $count = 0 Then
                MsgBox(0, "Error", "Please select a user")
            Else
                $ListIndices = _GUICtrlListViewGetSelectedIndices ($List1, 1)
            EndIf
            If $ListIndices == $LV_ERR Then ContinueLoop
            If $ListIndices[0] > 1 Then
                For $i = 1 To $count
                    RegWrite("HKEY_USERS\" & $ListIndices[$i - 1] & "\Software\Microsoft\Office\8.0\Outlook\Printing", "Print Settings File", "reg_sz", "C:\OutlPrnt")
                Next
            EndIf
        Case $msg = $Exitbutton
            Exit
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Exit

;===============================================================================
; Function Name: _UserSID()
;
; Description: Return a 2 dimensional array first username second SID.
;
; Syntax: _UserSID ( [$s_UserName, $s_RemoteComputer] )
;
; Parameter(s): $s_UserName = Username to get SID.
; $s_RemoteComputer = ComputerName on the network
;
; Requirement(s): External: = None.
; Internal: = None.
;
; Return Value(s): On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0.
; On Failure: = Returns "" and sets @error to 1.
;
; Author(s): Dan Colón
;
; Note(s):
;
; Example(s):
; _UserSID("DColon") it will return DColon SID
; _UserSID() it will return every user SID
;===============================================================================

Func _UserSID($s_UserName = "All", $s_RemoteComputer = '')
    If $s_UserName = '' Then $s_UserName = 'All'
    If $s_RemoteComputer <> '' Then
        If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then
            $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
        EndIf
    EndIf
    
    Local $line, $var, $ProfilePath, $i = 1
    Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
    Local Const $regkeyval1 = "ProfilesDirectory"
    Local Const $regkeyval2 = "ProfileImagePath"
    
    $ProfilePath = RegRead($regkey, $regkeyval1)
    While 1
        $line = RegEnumKey($regkey, $i)
        $var = RegRead($regkey & $line, $regkeyval2)
        If @error = 1 Or @error = -1 Then ExitLoop
        If $s_UserName == "All" Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        EndIf
        $i = $i + 1
    WEnd
    If Not IsDeclared("aArray") Then
        SetError(1)
        Return ("")
    Else
        SetError(0)
        Return ($aArray)
    EndIf
EndFunc  ;==>_UserSID
Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

Don't reopen old threads for something you JUST opened a thread for.

sorry about that but i realy need this... cause it will help me a lot with my work..thank you and realy sorry about that but i'm not a spammer >_<

Link to comment
Share on other sites

  • 8 years later...

hello , ı want to use this func. I am sorry for my bad english.  I dont know english. My code is failed. Please help me :D

My code ;

#RequireAdmin

$SID = _UserSID(@UserName, @ComputerName)
RegWrite("HKEY_USERS\" & $SID & "\Software\TunesKit\311","data4","REG_SZ","1")

Func _UserSID($s_UserName = "All", $s_RemoteComputer = '')
    If $s_UserName = '' Then $s_UserName = 'All'
    If $s_RemoteComputer <> '' Then
        If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then
            $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
        EndIf
    EndIf

    Local $line, $var, $ProfilePath, $i = 1
    Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
    Local Const $regkeyval1 = "ProfilesDirectory"
    Local Const $regkeyval2 = "ProfileImagePath"

    $ProfilePath = RegRead($regkey, $regkeyval1)
    While 1
        $line = RegEnumKey($regkey, $i)
        $var = RegRead($regkey & $line, $regkeyval2)
        If @error = 1 Or @error = -1 Then ExitLoop
        If $s_UserName == "All" Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line
            $aArray[0][0] = UBound($aArray) - 1
        EndIf
        $i = $i + 1
    WEnd
    If Not IsDeclared("aArray") Then
        SetError(1)
        Return ("")
    Else
        SetError(0)
        Return ($aArray)
    EndIf
EndFunc

I want this reg write for all users. Thanx 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...