Jump to content

Registry Read-Create-Import


 Share

Recommended Posts

I'm trying to create a tool that will do the following:

1. ENUM This Key:

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"

2. Then read the value of:

"ProfileImagePath"

3. Stop when it finds "%SystemDrive%\Documents and Settings\User"

4. Create file "ss.reg" using the key it found the value in 3.

5. Import the reg file siliently

6. Delete the file

Here's What I have for code. It does work, but I'm looking to see if there is any better and easier way to do it. One thing I can't figure out is if it can't locate %SystemDrive%\Documents and Settings\User" I need it to stop. Is there some kind of timer? The msgbox's are just to know what it's doing.

#include <file.au3>
;-----------------------------------------------------------------------------
$i = 0
Dim $line
$regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
$regkeyval = "ProfileImagePath" 
$sharelocation = "\\whatevershare\Scripts\RegistryReadProfiles\"
$batchfile = "regimport.bat"
;-----------------------------------------------------------------------------
Do
    $line = RegEnumkey($regkey,$i)
    $var = RegRead ( $regkey & $line, $regkeyval)
        $i = $i + 1
    If @error = 1 Then ExitLoop
        
Until $var = "%SystemDrive%\Documents and Settings\Kane"

Msgbox(0,"Found User Profile","Found it at SID:" & $line & @CR & "Key is:" & $var)

If $var = "%SystemDrive%\Documents and Settings\Kane"  Then
    
    _FileCreate("ss.reg")
    $file = FileOpen("ss.reg", 1)

         If $file = -1 Then
               MsgBox(0, "Error", "Unable to open file.")
         Exit
         EndIf

    FileWriteLine($file, "REGEDIT4")
    FileWriteLine($file, "[HKEY_USERS\" & $line & "\Control Panel\Desktop\WindowMetrics]")
    FileWriteLine($file, '"ScrollHeight"="-225"')
    FileWriteLine($file, '"ScrollWidth"="-225"')
    FileClose($file)
    RunWait($sharelocation & $batchfile,"")
    FileDelete ( "ss.reg" )
    MsgBox(64,"Success","Everything Worked Well")
Else
    Msgbox(0,"Not Good","I don't want to create the file")
EndIf

Thanks!

Link to comment
Share on other sites

4. Create file "ss.reg" using the key it found the value in 3.

5. Import the reg file siliently

6. Delete the file

<{POST_SNAPBACK}>

Would the RegWrite function be better than the 3 steps above?

Not sure what to suggest about your other question....

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Here's the updated version. Anyone Else have any ideas?

;--------------------------------------Variables-------------------------------------------
#include <file.au3>
$i = 0
Dim $val
$regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
$regkeyval = "ProfileImagePath" 
;------------------------------------------CODE--------------------------------------------
Do
    $val = RegEnumkey($regkey,$i)
    $var = RegRead ( $regkey & $val, $regkeyval)
    $i = $i + 1
    If @error = 1 Then ExitLoop
Until $var = "%SystemDrive%\Documents and Settings\Kane"

;Msgbox(0,"Found User Profile","Found it at SID:" & $val & @CR & "Key is:" & $var)

If $var = "%SystemDrive%\Documents and Settings\Kane"  Then

    RegWrite('HKEY_USERS\' & $val & '\Control Panel\Desktop\WindowMetrics',"ScrollHeight", "REG_SZ", "-225")
    RegWrite('HKEY_USERS\' & $val & '\Control Panel\Desktop\WindowMetrics',"ScrollWidth", "REG_SZ", "-225") 
    
;MsgBox(64,"Success","Everything Worked Well")
Else
;Msgbox(0,"Not Good","I don't work")
EndIf
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...