jaja714 Posted November 4, 2019 Share Posted November 4, 2019 I cannot get the RunAs example (from f1) working ... RunAs fails (@error=1) every time! #include <AutoItConstants.au3> Example() Func Example() ; Change the username and password to the appropriate values for your system. Local $sUserName = "myUsername" Local $sPassword = "myPassword" ; Run Notepad with the window maximized. Notepad is run under the user previously specified. Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, $RUN_LOGON_NOPROFILE, "notepad.exe", "", @SW_SHOWMAXIMIZED) ; Wait 10 seconds for the Notepad window to appear. WinWait("[CLASS:Notepad]", "", 10) ; Wait for 2 seconds. Sleep(2000) ; Close the Notepad process using the PID returned by RunAs. ProcessClose($iPID) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
TheXman Posted November 4, 2019 Share Posted November 4, 2019 So you have been around since 2009 and cannot figure out why a simple RunAs example doesn't work? This ought to be interesting. Can I assume that you at least used a valid username and password when you ran the example? Because when I use a valid username and password, the example script executes without any issues. But when I use invalid credentials, the RunAs() function fails with an @error = 1. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
jaja714 Posted November 4, 2019 Author Share Posted November 4, 2019 Ha ... I did use valid username and password! I actually used @username for the username. I guess I'm not quite sure of the interplay between RunAs and RequireAdmin. I am hoping that validating credentials on @computername would not require admin. Also, this is the first time I am scripting on my work laptop. I was hoping to authenticate locally (domain=@computername) so that I don't have to require being behind the firewall. Do you think I have to prefix the username with the domain name ("domain\@username") or something? Link to comment Share on other sites More sharing options...
TheXman Posted November 4, 2019 Share Posted November 4, 2019 (edited) I'm sure you read the remarks section for the RunAs command. It has several prerequisites for the RunAs function to be able to execute without an error. 39 minutes ago, jaja714 said: I was hoping to authenticate locally (domain=@computername) so that I don't have to require being behind the firewall. Do you think I have to prefix the username with the domain name ("domain\@username") or something? This depends on whether you need to use a local or domain account. If you want to see what the @Username macro resolves to, just use a consolewrite or msgbox to view the value. 39 minutes ago, jaja714 said: I guess I'm not quite sure of the interplay between RunAs and RequireAdmin. The easiest way to see the difference between using RunAs and #RequireAdmin is to first read the help file and then, if necessary, create a simple script with each and see the difference in how they execute. Edited November 4, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
jaja714 Posted November 4, 2019 Author Share Posted November 4, 2019 (edited) Ahah! logon_flag (p4) must be: $RUN_LOGON_NETWORK (2) - Network credentials only. Also, "domain\" prefix is optional, it works with or without it, in my case at least. $pid = 0 For $ii = 1 to 4 ConsoleWrite($ii&@TAB&RunAs( @UserName, @ComputerName, $sPassword, $ii, @SystemDir & '\calc.exe', @DesktopDir, @SW_SHOWMAXIMIZED)&@CRLF) ConsoleWrite($ii&@TAB&RunAs('domain\'&@UserName, @ComputerName, $sPassword, $ii, @SystemDir & '\calc.exe', @DesktopDir, @SW_SHOWMAXIMIZED)&@CRLF) Next Edited November 4, 2019 by jaja714 network Link to comment Share on other sites More sharing options...
jaja714 Posted June 15, 2020 Author Share Posted June 15, 2020 Resurrecting this again ... having problems ... here is some test code below: #RequireAdmin ; is this really needed? #include <AutoItConstants.au3> $realPass = '' ; <== type your real working password here $x = RunAs(@UserName, @ComputerName, $realPass, $RUN_LOGON_NETWORK, @ComSpec & " /c echo checking password...", @TempDir, @SW_HIDE) ConsoleWrite('REAL' & @TAB & @error & @TAB & $x & @CRLF) $failPass = 'failfailfailfail' ; this password should fail $x = RunAs(@UserName, @ComputerName, $failPass, $RUN_LOGON_NETWORK, @ComSpec & " /c echo checking password...", @TempDir, @SW_HIDE) ConsoleWrite('FAIL' & @TAB & @error & @TAB & $x & @CRLF) (a) is #Require Admin really needed? It is not in the RunAs help. (b) When I run this, it should FAIL on the second example, but it doesn't. I get this: >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Tools\AutoIt\test.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop REAL 0 17588 FAIL 0 18700 +>18:49:49 AutoIt3.exe ended.rc:0 +>18:49:49 AutoIt3Wrapper Finished. Link to comment Share on other sites More sharing options...
jaja714 Posted June 15, 2020 Author Share Posted June 15, 2020 oooh... my 100th post! Link to comment Share on other sites More sharing options...
jaja714 Posted June 16, 2020 Author Share Posted June 16, 2020 For anyone having the same issues, the best solution I could find is this: #include <Process.au3> ConsoleWrite('real' & @TAB & _RunDos('net use \\%userdnsdomain% /user:%userdomain%\%username% ' & 'realpass') & @CRLF) ; type your real working password here ConsoleWrite('fail' & @TAB & _RunDos('net use \\%userdnsdomain% /user:%userdomain%\%username% ' & 'fAiLpAsS') & @CRLF) ; this password should fail Exit Link to comment Share on other sites More sharing options...
jaja714 Posted September 18, 2020 Author Share Posted September 18, 2020 Well, now even this doesn't work anymore. Why is all this a moving target? >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\jeff.x.allen\git\idaa_tools\AutoIt\temp.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop real 2 fail 2 +>10:38:45 AutoIt3.exe ended.rc:0 +>10:38:45 AutoIt3Wrapper Finished. Link to comment Share on other sites More sharing options...
jaja714 Posted September 21, 2020 Author Share Posted September 21, 2020 (edited) Hmmm... I think the following line is needed before and after each attempt: _RunDos('net use \\' & @ComputerName & '\IPC$ /delete') Edited September 21, 2020 by jaja714 Link to comment Share on other sites More sharing options...
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