Jinseng Posted March 11, 2016 Share Posted March 11, 2016 I'm trying to write a script to open an Active Directory domain Group Policy, drill down to the password protected screensaver setting and open it (so I can manually set it to what I want at the time). It has to be done at the domain policy level so that it takes effect on all systems in the network. This used to work on a different version of Windows, but on Windows 2012 R2 I'm having problems with the script skipping commands in the middle. Specifically, it's skipping the send ("Admin") and send ("{RIGHT}") commands in the middle of my script which throws off every thing else it does. If I hand key the commands into windows everything happens as I expect it to, so I know the keys I'm sending do what I want. It just doesn't get executed properly by AutoIT. Anyone have any thoughts? Here's my script: Run(@ComSpec & " /c gpme.msc", "", @SW_HIDE) WinWait("Browse for a Group Policy Object") WinActivate("Browse for a Group Policy Object") WinWaitActive("Browse for a Group Policy Object") ; Select Policy Send("{TAB}") sleep(600) Send("wat") sleep(600) Send("{ENTER}") sleep(600) Send("{ENTER}") ; Browse to "Password protect the screen saver" policy and select it send("user") ;Select User Configuration sleep(600) send("pol") sleep(600) send("{RIGHT}") ;Expand Policies sleep(600) send("Admin") sleep(600) send("{RIGHT}") ;Expand Administrative Template sleep(600) send("control") sleep(600) send("{RIGHT}") ;Expand Control Panel sleep(600) send("pers") sleep(600) send("{TAB}") ;Select the right side of the screen sleep(600) send("password") ;Select Password protect the screen saver sleep(600) send("{ENTER}") Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2016 Share Posted March 11, 2016 (edited) I suspect you will need #RequireAdmin in your script on this version of windows. A non elevated script cannot interact with an elevated window. Edited March 11, 2016 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
water Posted March 11, 2016 Share Posted March 11, 2016 Welcome to AutoIt and the forum! Do you think a script is the best way to password protect the screensaver? As it is being done on the domain policy level you just need to do it once. Or am I wrong? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jdelaney Posted March 12, 2016 Share Posted March 12, 2016 Seriously, why script something where you can do a one liner in powershell, and get the same results. Also, you are using the most fundamental commands, which have no assurances that they are doing what you expect them to do. I always enjoy scripts like this from new users, it makes me want to vote for the 'recorder' to be deleted...it does more harm than good. 1) What assurances do you have (with the functions you used) that the window you are sending/clicking at is visible, active, enabled, not loading (ghosted)? 2) What assurances do you have (with the functions you used) that the control you are sending/clicking exists, is focused, and is enabled? 3) What assurances do you have (with the functions you used) that the popup windows that occur from a click, or selection, is present? The answer to all of the above is none...if you want to automate something so that it works 99% of the time you must take all of the above into consideration. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Jinseng Posted March 25, 2016 Author Share Posted March 25, 2016 Thank you all for the fast replies, and I'm sorry about my delayed response. This forum didn't notify me of your responses and it fell to the side at work. JohnOne, I'm not familiar with #RequireAdmin, but I did learn the hard way that the script won't run unless I compile it and run the .exe As Administrator. Doing it that way works fine with me. I just tried adding that at the top of the script and copying it locally (because I can't run a script from a network share while my permissions are elevated) and I still have the same issue. Water, Once I get to that setting I enable or disable it as necessary. I sometimes need to perform maintenance tasks on all of the servers in our network (50+ servers) at one time. I RDP into them, work on them for a bit, reboot, repeat until done. Having to enter my password very frequently is time consuming and really annoying so I disable the password protected screensaver while I'm running maintenance and then I re-enable it when I'm done. I do it at the domain level so that it takes effect everywhere. jdelaney, If you know of a PowerShell script/command I can use to modify a Domain Group policy setting, please point me in the right direction. I hate having to script this like this, but I've never found any PowerShell scripts to actually modify settings inside a Group policy. I've only seen PowerShell commands to work on the Group policy it's self, not the actual settings inside it. As for your questions related to the robustness of my script, it always worked on a previous version of Windows as long as I didn't do anything else while this 30 second script runs. Given that I'm writing and running this for myself, I'm OK with that restriction. Previously I was using a lot of arrow commands and decided to switch to typing names to make it a little more robust. I thought my three Win... commands near the top assured me that the correct window is opened. I just tried adding a set for "Group Policy Management Editor", but that didn't help. I have the sleep commands in there to give windows time to perform the actions. Also, while watching the script, it does exactly what I want until the part listed above where it skips two commands and then continues with the rest of them (it always skips at this point). I came to this forum for help figuring out why my script doesn't perform the tasks outlined in it. If you have other commands that I should add to the script to ensure it does what I've outlined above, then please tell me what they are and where to place them. This is the only script I've ever written, so I'm looking for specific suggestions and help. Any other thoughts or things I should try? Link to comment Share on other sites More sharing options...
Jinseng Posted March 30, 2016 Author Share Posted March 30, 2016 I played with this more and finally got the script working. It looks messy to me and I didn't think I'd have to do this, but since it works I'm OK with it. Here's my updated script for anyone else having a similar issue. There may be better ways of doing this, but I don't know what they are. #RequireAdmin Run(@ComSpec & " /c gpme.msc", "", @SW_HIDE) WinWait("Browse for a Group Policy Object") WinActivate("Browse for a Group Policy Object") WinWaitActive("Browse for a Group Policy Object") ; Select Policy Send("{TAB}") sleep(600) Send("wat") sleep(600) Send("{ENTER}") sleep(600) Send("{ENTER}") WinWait("Group Policy Management Editor") WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") ; Browse to "Password protect the screen saver" policy and select it send("user") ;Select User Configuration sleep(600) WinActivate("Group Policy Management Editor");These win... commands are repeated each time to ensure the commands are processed properly. Without them the script skips commands WinWaitActive("Group Policy Management Editor") send("pol") sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("{RIGHT}") ;Expand Policies sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("Admin") sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("{RIGHT}") ;Expand Administrative Template sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("control") sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("{RIGHT}") ;Expand Control Panel sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("pers") sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("{TAB}") ;Select the right side of the screen sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("password") ;Select Password protect the screen saver sleep(600) WinActivate("Group Policy Management Editor") WinWaitActive("Group Policy Management Editor") send("{ENTER}") 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