Duck Posted November 16, 2015 Share Posted November 16, 2015 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\UseOEMBackgroundMy 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 More sharing options...
Moderators JLogan3o13 Posted November 16, 2015 Moderators Share Posted November 16, 2015 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 Duck 1 "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 More sharing options...
Duck Posted November 17, 2015 Author Share Posted November 17, 2015 Thank you very much for the warm welcome and the solution to my question. This works like a charm. Link to comment Share on other sites More sharing options...
Duck Posted November 17, 2015 Author Share Posted November 17, 2015 ...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 More sharing options...
AdamUL Posted November 17, 2015 Share Posted November 17, 2015 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 ;==>_EnableWin7CustomLogonBackgroundHopefully this is helpful. Adam Duck 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now