Emolas Posted July 24, 2012 Posted July 24, 2012 I'm trying to set auto logon using the userpasswords2 control because it is a bit more secure than plain text passwords in the registry. I tried a few approaches but none of them work. here is what I have that goes the farthest: $User = "TestUser" $Pass = "Password1" Run(@ComSpec & " /c " & 'control userpasswords2', "", @SW_HIDE) WinWaitActive ("User Accounts", "Users must &enter a user name and password to use this computer.") Send("!e" & "!a") WinWaitActive ("Automatically Log On") Send("!u" & $user & "!p" & $pass & "!c" & $pass & "{ENTER}") WinWaitActive ("User Accounts") Send("{ENTER}") Everything works fine right up until it gets to the "ENTER" part of the Send("!u" & $user & "!p" & $pass & "!c" & $pass & "{ENTER}") line. Windows gives one of those "you did something wrong" noises and the window stays open. I can manually hit the enter key and it proceeds as normal but the scripting of it does not work. This one goes almost as far as the previous one: $User = "TestUser" $Pass = "Password1" Run("control userpasswords2") WinWaitActive("User Accounts") Send("{space}{ENTER}") WinWaitActive("Automatically Log On") Send("+{TAB}" & $User & "{TAB}" & $pass & "{TAB}" & $pass & "{ENTER}") WinWaitActive ("User Accounts") Send("{ENTER}") It one works right up until it is supposed to tab to the second password and then it tabs to a different window like alt-tab. The final one I tried does nothing after running the control. I'm not even certain if I am using the commands correctly. $User = "TestUser" $pass = "Password1" Run("control userpasswords2") WinWaitActive("User Accounts") ControlClick("User Accounts","","[CLASS:Button; INSTANCE:1]") ControlClick("User Accounts","","[CLASS:Button; INSTANCE:9]") WinWaitActive("Automatically Log On") ControlSetText("Automatically Log On","","[CLASS:Edit; INSTANCE:1]",$User) ControlSetText("Automatically Log On","","[CLASS:Edit; INSTANCE:2]",$pass) ControlSetText("Automatically Log On","","[CLASS:Edit; INSTANCE:3]",$pass) ControlClick("Automatically Log On","","[CLASS:Button; INSTANCE:1]") WinWaitActive("User Accounts") ControlClick("User Accounts","","[CLASS:Button; INSTANCE:7]") So I have three options, all of which look like they should work (to me anyway) but none of which work. Is there something stupid I am missing?
dmob Posted July 24, 2012 Posted July 24, 2012 All the commands in the third script have return values and error codes. Check those to find out which commands are failing.
Emolas Posted July 24, 2012 Author Posted July 24, 2012 All the commands in the third script have return values and error codes. Check those to find out which commands are failing. added variables to each command to log errors and msgboxes to report them but there are no errors. It loads up the User Accounts windows and sits there. If I click on the next two steps manually (ControlClick("User Accounts","","[CLASS:Button; INSTANCE:1]") & ControlClick("User Accounts","","[CLASS:Button; INSTANCE:9]")), it finishes the rest without a problem but it seems WinWaitActive("User Accounts") never realizes it is active so it hangs there. Interestingly, this is a snip from a much larger script and it works alone but not within the original script.
Moderators Melba23 Posted July 24, 2012 Moderators Posted July 24, 2012 Emolas,Did it occur to you that these login dialogs are set up to resist automation (for perfectly understandable reasons)? In my opinion this falls foul of the prohibition on login scripts and so will be locked forthwith. Please read the Forum Rules before posting again. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts