AutoHotkey Community

It is currently May 25th, 2012, 7:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: February 2nd, 2005, 1:01 pm 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: things I've tried
PostPosted: February 2nd, 2005, 1:08 pm 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
I have tried the following, all same results...

Run vs RunWait
With & without computername
Other "dummy" programs such as Calc & Notepad with a WinClose
Without UseErrorLevel, just looking for runtime errors
Extra RunAs commands with dummy user & password parameters

and yes... Secondary Logon service is running

Help!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 2:26 pm 
Assumption. The script will loop indefinitely. So the PW once entered correctly will be kept and used again and agai and again and ...

Maybe I'm wrong, but what about to reset it once it has been approved to be correct ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2005, 6:42 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This has been fixed in today's update. Thanks for reporting it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks
PostPosted: February 2nd, 2005, 10:58 pm 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
BoBo,
The script given was just a test example to show the error, the code is part of a much larger script.

Chris,
Thanks for that, I will try it out and let you know how it goes.

I also did get another method working, that was to use FileAppend to create a small script, then RunWait to execute it. And I found you can use hh.exe as a dummy program to do nothing (it's used to display html help normally)

Code:
Loop
{
  InputBox,pw,Password,,Hide,140,100
  If ErrorLevel
    Exit

  GoSub,PassCheck
  TrayTip,,%pw%
}


PassCheck:
  FileAppend,#NoTrayIcon`n RunAs`,%A_UserName%`,%pw%`n RunWait`,hh.exe`,`,UseErrorLevel`n RunAs`n If ErrorLevel=ERROR`n Exit`,1`n Else`n Exit`,0`n,%temp%\temp.ahk
  RunWait,%temp%\temp.ahk,,UseErrorLevel
  If ErrorLevel=1
    pw=incorrect
  Else
    pw=ok
  FileDelete,%temp%\temp.ahk
Return


I still wasn't completely happy with this though...


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Happy now :-)
PostPosted: February 2nd, 2005, 11:15 pm 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
Great, Chris

Now it works as I expected. Also works for my own password or any other user too. Here's my working code to validate administrator password...

Code:
Loop
{
  InputBox,pw,Password,,Hide,140,100
  If ErrorLevel
    Exit

  User=administrator ; or User=%A_UserName% or User=Mike
  GoSub,PassCheck
  TrayTip,,%pw%
}


PassCheck:
  RunAs,%User%,%pw%
  RunWait,hh.exe,,UseErrorLevel
  RunAs
  If ErrorLevel=ERROR
    pw=incorrect
  Else
    pw=ok
Return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: gemisigo, lblb, Maestr0, MilesAhead, Yahoo [Bot] and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group