Jump to content

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


Duck
 Share

Recommended Posts

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?

 

 

Link to comment
Share on other sites

  • Moderators

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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. 

 

Link to comment
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

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