Jump to content

how to copy a whole reg path as admin/user


Recommended Posts

hi

the only way i have found out to copy a whole reg path is using Run().

for administrative tasks i use Run() with RunAsSet().

it works, but it is rather slow. especially when processing many reg paths.

is there a better solution for copying reg paths? E. g. using DllCall(), etc. ???

Edited by supersonic
Link to comment
Share on other sites

hi

the only way i have found out to copy a whole reg path is using Run().

for administrative tasks i use Run() with RunAsSet().

it works, but it is rather slow. especially when processing many reg paths.

is there a better solution for copying reg paths? E. g. using DllCall(), etc. ???

I don't get what exactly you want to do. Can you give us exsamples?

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

i try to describe:

i'm logged in with user rights only and starting an au3-script.

this script loads an input file with many (> 450) mixed reg keys/entries (HKCU, HKLM, HKU) to write.

as i mentioned before i'm logged in with user rights only, so i have to switch to admin rights in order to

write keys/entries in HKLM or KHU. my current code creates an array and feeds a function to get the job done (see code example below).

fact is: using Run() could be rather slow. i'm looking for a way to speed this job more up...

as far as i know RegWrite(), etc. can't handle user context switching...

The code works pretty fine so far...

Func reg($regTarget)
    $regArray = xmlQueryGV($regTarget)
    If $regArray = 2 Then
        Return 2
    Else
        RunAsSet("Administrator", $envLogonDomain, $envPassword)
        For $i = 1 to $regArray[0]
            $x = StringSplit($regArray[$i], ";", 0)
            If $x[0] >= 3 Then
                If $x[0] = 3 Then
                    $regKeyRoot = $x[2]
                    $regKeyPath = StringReplace(StringReplace($x[3], _
                        Chr(034),       "",         0, 0), _
                        "$USERSID$",    $userSID,   0, 0)
                    If $x[1] = "RegDelete" Then
                        If  StringInStr($regKeyRoot, "HKLM",    0) Or _
                            StringInStr($regKeyRoot, "HKU",     0) Then
                                Run(@ComSpec & " /C " & @SystemDir & "\reg.exe DELETE " & Chr(034) & $regKeyRoot & "\" & $regKeyPath & Chr(034) & " /F", @TempDir, @SW_HIDE)
                        Else
                            RegDelete("HKU\" & $userSID & "\.\" & $regKeyRoot & "\" & $regKeyPath)
                        EndIf
                    ElseIf $x[1] = "RegWrite" Then
                        RegWrite("HKU\" & $userSID & "\.\" & $regKeyRoot & "\" & $regKeyPath)
                    EndIf
                Else
                    If $x[0] = 4 Then
                        $regKeyRoot = $x[2]
                        $regKeyPath = StringReplace(StringReplace($x[3], _
                            Chr(034),       "",         0, 0), _
                            "$USERSID$",    $userSID,   0, 0)
                        $regName = StringReplace($x[4], Chr(034), "", 0, 0)
                        If $x[1] = "RegDelete" Then
                            If  StringInStr($regKeyRoot, "HKLM",    0) Or _
                                StringInStr($regKeyRoot, "HKU",     0) Then
                                    Run(@ComSpec & " /C " & @SystemDir & "\reg.exe DELETE " & Chr(034) & $regKeyRoot & "\" & $regKeyPath & Chr(034) & " /V " & Chr(034) & $regName & Chr(034) & " /F", @TempDir, @SW_HIDE)
                            Else
                                RegDelete("HKU\" & $userSID & "\.\" & $regKeyRoot & "\" & $regKeyPath, $regName)
                            EndIf
                        ElseIf $x[1] = "RegWrite" Then
                            RegWrite("HKU\" & $userSID & "\.\" & $regKeyRoot & "\" & $regKeyPath, $regName)
                        EndIf
                    Else
                        If $x[0] = 6 Then
                            $regKeyRoot = $x[2]
                            $regKeyPath = StringReplace(StringReplace($x[3], _
                                Chr(034),       "",         0, 0), _ 
                                "$USERSID$",    $userSID,   0, 0)
                            $regName = StringReplace($x[4], Chr(034), "", 0, 0)
                            $regType = StringReplace(StringReplace(StringReplace(StringReplace($x[5], _
                                "0x00000000", "REG_SZ",         0, 0), _
                                "0x00000001", "REG_BINARY",     0, 0), _
                                "0x00010001", "REG_DWORD",      0, 0), _
                                "0x00020000", "REG_EXPAND_SZ",  0, 0)
                            $regData = StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($x[6], _
                                "$ANDSIGN$",        "&",                            0, 0), _
                                "$LOCAL$",          "<local>",                      0, 0), _
                                "$LOGONSERVER$",    StringUpper($envLogonServer),   0, 0), _
                                "$SEMICOLON$",      ";",                            0, 0), _
                                "$USERNAME$",       StringUpper(@UserName),         0, 0)
                            If $x[1] = "RegDelete" Then
                                ; <...>
                            ElseIf $x[1] = "RegWrite" Then
                                RegWrite("HKU\" & $userSID & "\.\" & $regKeyRoot & "\" & $regKeyPath, $regName, $regType, $regData)
                            EndIf
                        EndIf
                    EndIf
                EndIf
            EndIf
        Next
        RunWait(@ComSpec & " /C " & _
            @SystemDir & "\reg.exe COPY " & _
                Chr(034) & "HKU\" & $userSID & "\.\HKLM" & Chr(034) & " " & _
                Chr(034) & "HKLM" & Chr(034) & " /F /S" & "&" & _
            @ComSpec & " /C " & _
            @SystemDir & "\reg.exe COPY " & _
                Chr(034) & "HKU\" & $userSID & "\.\HKU" & Chr(034) & " " & _
                Chr(034) & "HKU" & Chr(034) & " /F /S", @TempDir, @SW_HIDE)
        RunAsSet()
        RunWait(@ComSpec & " /C " & _
            @SystemDir & "\reg.exe COPY " & _
                Chr(034) & "HKU\" & $userSID & "\.\HKCU" & Chr(034) & " " & _
                Chr(034) & "HKCU" & Chr(034) & " /F /S", @TempDir, @SW_HIDE)
        RegDelete("HKU\" & $userSID & "\.")
        Return 0
    EndIf
EndFunc

first i collect all reg keys/entries in "HKU\$userSID", so i can use Run() to write them in single step.

Deleting in HKCU is performed directly, deleting in HKLM or HKU requires Run().

hi

I don't get what exactly you want to do. Can you give us exsamples?

Regards, Rudi.

Edited by supersonic
Link to comment
Share on other sites

Hi.

so when you just want to write many, many values to the registry, write what you need to some TEMP.REG file and import that one silently using

regedit /s temp.reg

Howto read faster? Check the capabilities of REG.EXE...

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

The input file is based on XML and it should be the only file where ALL reg keys/entries are stored.

Hi.

so when you just want to write many, many values to the registry, write what you need to some TEMP.REG file and import that one silently using

regedit /s temp.reg

Howto read faster? Check the capabilities of REG.EXE...

Regards, Rudi.

Link to comment
Share on other sites

The input file is based on XML and it should be the only file where ALL reg keys/entries are stored.

As registry keys + vals a user can write to are also visible to the user, I can't see why it should be a problem working with a temporary REG file?

You can delete that file just the second regedit.exe has finished it's job. :)

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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...