Sign in to follow this  
Followers 0
Duck

Windows Registry - Finding the proper "{...}Machine\" path

5 posts in this topic

I am writing a simple program where I am attempting to modify local group policy with a registry modification to keep persistence for changing the lock screen background on windows 7. I thought it would be a good project to help me learn AutoIt. I am scripting this write up: http://www.howtogeek.com/112110/how-to-set-a-custom-logon-screen-background-on-windows-7/

I have it completed and it is working well except the portion where i modify the local group policy. If i move my app to another computer it no longer works as the "{F84981F1-D7CF-45BD-A6FA-606FF4F9D1B1}Machine" portion of the path changes from computer to computer. 

The Key that is being modified is: HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{F84981F1-D7CF-45BD-A6FA-606FF4F9D1B1}Machine\Software\Policies\Microsoft\Windows\System\UseOEMBackground

My question is how do i dynamical assign the "{F84981F1-D7CF-45BD-A6FA-606FF4F9D1B1}Machine" portion of the path to reflect the correct path on any computer?

 

 

Share this post


Link to post
Share on other sites



Hi, @Duck welcome to the forum. You can always enumerate the keys in the registry to find the one you need:

$sKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects"

For $i = 1 to 10
    Local $sSubKey = RegEnumKey($sKey, $i)
        If StringInStr($sSubKey, "}Machine") Then ConsoleWrite($sSubKey & @CRLF)
Next

 

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Thank you very much for the warm welcome and the solution to my question. This works like a charm. 

Share this post


Link to post
Share on other sites

...However i have realized after a bit more testing that the Group Policies have to be modified before a "Group Policy Object\{...}Machine\..." directory is made. This proves to be unreliable with freshly imaged PCs in my particular case. Any advice on how i should go about modifying the local group policies? Should i attempt to modify it like scripting an installer, calling gpedit.msc? Any advise is greatly appreciated. 

 

Share this post


Link to post
Share on other sites

For our imaging script, I wrote a function to do just what you are trying to do.  The function that I wrote pulls the images off of a server share, and copy them to "backgrounds" directory.  This function is part of a much larger script, so you may need to edit them to do what you need.  

Func _EnableWin7CustomLogonBackground($sUserName, $sPassword, $sServerShare) ;Copies the Logon UI backgrounds from a server share and turn the setting on in the registry.
    $sUserName = StringStripWS($sUserName, 8)
    If Not StringInStr($sUserName, "AD\") Then $sUserName = "AD\" & StringStripWS($sUserName, 8)

    Local Const $sOobeDir = @SystemDir & "\oobe"
    Local Const $sBackgroundsDir = $sOobeDir & "\info\backgrounds"

    If Not FileExists($sOobeDir) Then Return SetError(2, 0, 0)

    DriveMapAdd("", $sServerShare, 0, $sUserName, $sPassword)
    If @error Then Return SetError(Number("100" & @error), @extended, 0)

    If Not DirCopy($sServerShare, $sBackgroundsDir, 1) Then Return SetError(2, 0, 0)
    
    Local $s64Bit = ""
    If @OSArch = "X64" Then $s64Bit = "64"
;~  If Not RegWrite("HKEY_LOCAL_MACHINE" & $s64Bit & "\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", "REG_DWORD", 1) Then Return SetError(4, @error, 0)  ;Use Logon UI Reg Key.
    If Not RegWrite("HKEY_LOCAL_MACHINE" & $s64Bit & "\Software\Policies\Microsoft\Windows\System", "UseOEMBackground", "REG_DWORD", 1) Then Return SetError(4, @error, 0) ;Use Policy Reg Key.

    Return 1
EndFunc   ;==>_EnableWin7CustomLogonBackground

Hopefully this is helpful.  

 

Adam

1 person likes this

Share this post


Link to post
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
Sign in to follow this  
Followers 0