Deon Posted March 29, 2014 Posted March 29, 2014 I'm working on a script which will run a program as another user, using RunAs The user is prompted for their alternate login details, and the variables $username and $password are passed to RunAs. Everything was working fine, until I noticed the program to be run stopped opening. An hour of debugging later, I've found the $username and $password variables are returning a static value for some reason. No matter what the user enters, $username returns '4' No matter what the user enters, $password returns '6' I've included a small piece of the code below, and this snippet seems to be replicating the problem. I've outputted both variables to the console in this snippet. Any assistance is greatly appreciated!! #include <GUIConstants.au3> ; Prompt the user for their login details $MAIN = GUICreate("USERNAME & PASSWORD", 220, 120) GUICtrlCreateLabel("USERNAME:", 10, 15, 65, 25) $USERNAME = GUICtrlCreateInput("", 80, 10, 120, 25) GUICtrlCreateLabel("PASSWORD:", 10, 55, 65, 25) $PASSWORD = GUICtrlCreateInput("", 80, 50, 120, 25) $OK = GUICtrlCreateButton("OK", 40, 85, 60, 25) $CANCEL = GUICtrlCreateButton("CANCEL", 120, 85, 60, 25) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Or $MSG = $CANCEL Exit Case $MSG = $OK GUIDelete($MAIN) ConsoleWrite("Username: " & $username & @CRLF & "Password: " & $password & @CRLF) Exit EndSelect Sleep(10) WEnd
Deon Posted March 29, 2014 Author Posted March 29, 2014 Console output: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Deon\Documents\runas.au3" Username: 4 Password: 6 >Exit code: 0 Time: 2.424
lorenkinzel Posted March 29, 2014 Posted March 29, 2014 You need to read the input & assign a variable to that. Just for username : #include <GUIConstants.au3> ; Prompt the user for their login details $MAIN = GUICreate("USERNAME & PASSWORD", 220, 120) GUICtrlCreateLabel("USERNAME:", 10, 15, 65, 25) $USERNAME = GUICtrlCreateInput("", 80, 10, 120, 25) GUICtrlCreateLabel("PASSWORD:", 10, 55, 65, 25) $PASSWORD = GUICtrlCreateInput("", 80, 50, 120, 25) $OK = GUICtrlCreateButton("OK", 40, 85, 60, 25) $CANCEL = GUICtrlCreateButton("CANCEL", 120, 85, 60, 25) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Or $MSG = $CANCEL Exit Case $MSG = $OK $theName = GUICtrlRead($USERNAME);>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GUIDelete($MAIN) ConsoleWrite("Username: " & $theName & @CRLF & "Password: " & $password & @CRLF) Exit EndSelect Sleep(10) WEnd I assume better explanations to follow, but that should get you moving forward.
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