Jump to content

Confirm Wndows Password?


Recommended Posts

One of my scripts asks the user to enter his/her Windows logon password so that it could be used in a command later on. Is there a way to confirm that the user entered the correct password before proceeding to run the actual commands?

I suppose what I'm asking for may be a harmless built-in Windows command that requires the Windows password, so that I can test the output from that command before getting the user into a mess later on.

Of course if there's a built-in AutoIt way to do this, that would be even better.

Thanks for any help.

Link to comment
Share on other sites

One of my scripts asks the user to enter his/her Windows logon password so that it could be used in a command later on. Is there a way to confirm that the user entered the correct password before proceeding to run the actual commands?

I suppose what I'm asking for may be a harmless built-in Windows command that requires the Windows password, so that I can test the output from that command before getting the user into a mess later on.

Of course if there's a built-in AutoIt way to do this, that would be even better.

Thanks for any help.

This works for me:

; Test RunAsSet credentials
; Performs an ECHO command at a CMD shell if credentials are good.

$UserPw = InputBox('RunAs Test', 'Enter you password: ', '', '*')
If Not RunAsSet(@UserName, '', $UserPw, 0) Then
    MsgBox(16, 'RunAs Error', 'Your OS does not support this feature (Win2K and above)...')
    Exit
EndIf

$ExtCmd = @ComSpec & ' /c echo "Testing credentials for: "' & @UserName
Opt("RunErrorsFatal", 0); 0=Do not exit, set @Error on fail
$RetCode = RunWait($ExtCmd, @TempDir, @SW_HIDE)
If @error Then
    MsgBox(16, 'RunAs Fail', 'The credentials failed for ' & @UserName & '!')
Else
    MsgBox(64, 'RunAs Pass', 'The credentials worked for ' & @UserName & '!')
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That works really well.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

  • 2 years later...

Unfortunately, the terrific code shown above no longer works with the latest version, presumably because RunAsSet and RunErrorsFatal are no longer supported. Following the help file, I've modified the code to open a command prompt, but I'm hoping to find something invisible instead. Any help greatly appreciated. Here's the revised code:

CODE
; Test RunAs credentials (revised)

; Performs an ECHO command at a CMD shell if credentials are good.

$UserPw = InputBox('RunAs Test', 'Enter your password: ', '', '*')

If Not RunAs(@UserName, '', $UserPw, 0, @ComSpec, @SystemDir) Then

MsgBox(16, 'RunAs Error', 'Your OS does not support this feature (Win2K and above)...')

Exit

EndIf

$ExtCmd = @ComSpec & ' /c echo "Testing credentials for: "' & @UserName

;Opt("RunErrorsFatal", 0); 0=Do not exit, set @Error on fail

$RetCode = RunWait($ExtCmd, @TempDir, @SW_HIDE)

If @error Then

MsgBox(16, 'RunAs Fail', 'The credentials failed for ' & @UserName & '!')

Else

MsgBox(64, 'RunAs Pass', 'The credentials worked for ' & @UserName & '!')

EndIf

Link to comment
Share on other sites

Unfortunately, the terrific code shown above no longer works with the latest version, presumably because RunAsSet and RunErrorsFatal are no longer supported. Following the help file, I've modified the code to open a command prompt, but I'm hoping to find something invisible instead. Any help greatly appreciated. Here's the revised code:

CODE
; Test RunAs credentials (revised)

; Performs an ECHO command at a CMD shell if credentials are good.

$UserPw = InputBox('RunAs Test', 'Enter your password: ', '', '*')

If Not RunAs(@UserName, '', $UserPw, 0, @ComSpec, @SystemDir) Then

MsgBox(16, 'RunAs Error', 'Your OS does not support this feature (Win2K and above)...')

Exit

EndIf

$ExtCmd = @ComSpec & ' /c echo "Testing credentials for: "' & @UserName

;Opt("RunErrorsFatal", 0); 0=Do not exit, set @Error on fail

$RetCode = RunWait($ExtCmd, @TempDir, @SW_HIDE)

If @error Then

MsgBox(16, 'RunAs Fail', 'The credentials failed for ' & @UserName & '!')

Else

MsgBox(64, 'RunAs Pass', 'The credentials worked for ' & @UserName & '!')

EndIf

Try this for 3.2.12.0 and later:
$UserPw = InputBox('RunAs Test', 'Enter your password: ', '', '*')

$RetCode = RunAs(@UserName, @ComputerName, $UserPw, 0, @ComSpec & " /c echo.", @TempDir, @SW_HIDE)
If @error = 0 And $RetCode <> 0 Then
    MsgBox(64, 'RunAs Pass', 'The credentials worked for ' & @UserName & '!')
Else
    MsgBox(16, 'RunAs Fail', 'The credentials failed for ' & @UserName & '!')
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Try this for 3.2.12.0 and later:

$UserPw = InputBox('RunAs Test', 'Enter your password: ', '', '*')

$RetCode = RunAs(@UserName, @ComputerName, $UserPw, 0, @ComSpec & " /c echo.", @TempDir, @SW_HIDE)
If @error = 0 And $RetCode <> 0 Then
    MsgBox(64, 'RunAs Pass', 'The credentials worked for ' & @UserName & '!')
Else
    MsgBox(16, 'RunAs Fail', 'The credentials failed for ' & @UserName & '!')
EndIf
Perfect! Thank you again!
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...