Bert Posted February 19, 2008 Posted February 19, 2008 When using the RunAsSet command, and a bad password is used, how do I code it so if that happens, I can put an @error to make it do a return so as to allow for the user to re-enter his password?? The Vollatran project My blog: http://www.vollysinterestingshit.com/
Developers Jos Posted February 19, 2008 Developers Posted February 19, 2008 Something like this ? Opt("RunErrorsFatal", 0) Global $UserId,$Password While 1 $UserId = InputBox("Username", "Enter Userid", $UserId) $Password = InputBox("Password", "Enter Password", "", "*") RunAsSet($UserId, @ComputerName, $Password) RunWait(@ComSpec & " /c dir ", "", @SW_HIDE) If Not @error Then ExitLoop MsgBox(4096, "Userid/Password Error", "Userid/Password Error... try again.") WEnd SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Bert Posted February 19, 2008 Author Posted February 19, 2008 (edited) I tried this, but I haven't tested it. $LA = _Security__LookupAccountName("$id) if $LA[2] = "" then MsgBox(0, "Error", "RACF entered in incorrectly or is not found. Please try again.", 10) Return EndIf if $LA[2] = 1 then $runit = ShellExecute($pt) if $runit = @error then MsgBox(0, "Error", "Password entered in incorrectly. Please try again.", 10) return endif exit EndIf ;if all error checks pass, then enable the runasset command. EndFunc Edited February 19, 2008 by Volly The Vollatran project My blog: http://www.vollysinterestingshit.com/
Developers Jos Posted February 19, 2008 Developers Posted February 19, 2008 I also posted this one before for checking against an AD to validate USer/Psw and optionally a Group... : $oMyError = ObjEvent("AutoIt.Error", "ComError") msgbox(0,"Validate",UserValidate(@LogonDomain,"unknown-user","userpwd")) msgbox(0,"Validate",UserValidate(@LogonDomain,"Okuser","userpwd")) msgbox(0,"Validate",UserValidate(@LogonDomain,"Okuser","userpwd","groupdoesnotexist")) msgbox(0,"Validate",UserValidate(@LogonDomain,"Okuser","userpwd","groupexist")) Exit ; Check Valid User/Password and optionally in a group Func UserValidate($domain, $UserName, $Password, $InGroup="") Local $NameSpace = ObjGet("WinNT:") Local $ADS_SECURE_AUTHENTICATION = 0x0001 Local $DomObj = $NameSpace.OpenDSObject("WinNT://" & $domain , $UserName, $Password, $ADS_SECURE_AUTHENTICATION) If @error <> 0 Then Return 0 If $InGroup <> "" Then $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName) For $oGroup in $objUser.Groups If $oGroup.Name = $InGroup Then Return 1 EndIf Next Return 0 EndIf Return 1 EndFunc ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) Else SetError(1) EndIf Return 0 EndFunc ;==>ComError SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Bert Posted February 19, 2008 Author Posted February 19, 2008 I'm trying to follow the code, but I'm not sure on how to use it. It looks like it does a check in AD, but then again, I do not know what the ComError does, and the msgboxs at the beginning...confused on that one. I assume I just need the uservalidate() function. I'm not sure on how to tell when the password is wrong on the return. The Vollatran project My blog: http://www.vollysinterestingshit.com/
Developers Jos Posted February 19, 2008 Developers Posted February 19, 2008 (edited) In case you specify just the Userid/Password, the uservalidate() will return 1 when the UserId & Password combination is correct else it will return a 0. When you add the Group parameter, the uservalidate() will additionally check if the User is part of the specified group. again it will return 1 when that's true else a 0. The Comerror function is needed to avoid the script to stop working in case of Comm error and required to test the validity of the Userid/pasword line since that will generate a comerror when its invalid. the next line tests for that. so a simple example to check the userid and password could be (untested): expandcollapse popup$oMyError = ObjEvent("AutoIt.Error", "ComError") If UserValidate(@LogonDomain,$UserId,$psw) then ; User validated Else ; Invalid User/password combination EndIf ; Check Valid User/Password and optionally in a group Func UserValidate($domain, $UserName, $Password, $InGroup="") Local $NameSpace = ObjGet("WinNT:") Local $ADS_SECURE_AUTHENTICATION = 0x0001 ; Check the userid/password combination and on error return a 0 Local $DomObj = $NameSpace.OpenDSObject("WinNT://" & $domain , $UserName, $Password, $ADS_SECURE_AUTHENTICATION) If @error <> 0 Then Return 0 ; Optionally check the group membership If $InGroup <> "" Then $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName) For $oGroup in $objUser.Groups If $oGroup.Name = $InGroup Then Return 1 EndIf Next Return 0 EndIf Return 1 EndFunc ; ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) Else SetError(1) EndIf Return 0 EndFunc;==>ComError Edited February 19, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Bert Posted February 19, 2008 Author Posted February 19, 2008 ahhh...now I understand. Thanks! The Vollatran project My blog: http://www.vollysinterestingshit.com/
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