Sideoutfan

RunAs with message box

4 posts in this topic

I'm trying to understand how to have a message box pop up if RunAs credentials are incorrect so user knows they may have typed their username or password incorrectly. Please provide suggestions. Can I do it within a Case as seen below whether adding a function that is called or something else? I'm not seeing such an option for notification within the RunAs parameters.

Case $Registry
            $Username = GUICtrlRead($UNI)
            $Password = GUICtrlRead($PWField)
            $Domain = GUICtrlRead($DomList)
            RunAs($Username, $Domain, $Password, $RUN_LOGON_PROFILE, "C:\Windows\regedit.exe")

 

Thank you for any help.

Share this post


Link to post
Share on other sites



RunAs will return a PID if the function is successful, 0 if it failed. You can throw your RunAs call in an If statement like this

#include <MsgBoxConstants.au3>

If (Not RunAs($Username, $Domain, $Password, $RUN_LOGON_PROFILE, "C:\Windows\regedit.exe")) Then
    MsgBox($IDOK, "Failed", "Failed to start regedit.exe as " & $Username & @CRLF & "Your credentials may be incorrect")
EndIf

 

Share this post


Link to post
Share on other sites

Wow InunoTaishou. Thank you so much! That is fantastic. I really appreciate your help. I don't know that I would have figured this out on my own as I am fairly new to AutoIT. I'm most grateful. Works perfectly!

Share this post


Link to post
Share on other sites

Np, almost every solution is already in the help file or has been answered. And almost all AutoIt functions return some kind of value letting you know if the function succeeded or failed, most will set the error flag to true (@Error) if it fails as well.

Share this post


Link to post
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