I'm not sure if perhaps this is a bug...
What I am trying to do is restrict actions in a script by prompting for a password first, and for security and maintenance reasons I'd like to use a windows password rather than coding one into the script. (specifically this is a time-limit application for my kids PC usage).
I thought I could use RunAs then Run with some dummy program and check errorlevel to see if the run was successful, and thus the username/password was correct. It all seems to work fine for the FIRST TIME in the script (ie. password ok, Run gives no error, password wrong, run gives an error), but subsequent checks always return no error. If the script is terminated and restarted, it works ONCE again.
Here's some sample code you can test this with. It prompts for a password (ie YOUR windows password) then tries to validate it using the method described. I've tried quite a few variations on this theme, but the only way I can make it work is make the passcheck routine a separate script then compile it and call it from my script. Not how I want it to work!
Code:
Loop
{
InputBox,pw,Password,,Hide,140,100
If ErrorLevel
Exit
GoSub,PassCheck
}
PassCheck:
RunAs,%A_UserName%,%pw%,@%A_ComputerName%
RunWait,%comspec% /c exit,,Hide UseErrorLevel ; This is just a dummy run that does nothing important
RunAs
If ErrorLevel=ERROR
TrayTip,,Password incorrect ; message for testing
Else
TrayTip,,Password ok
Return