Sign in to follow this  
Followers 0
LuI

Can anyone point me to the error codes of RunAs or Run?

7 posts in this topic

Hi all,

sorry for that Q, but I cant find my solution :-((

I try to call a console program using Run() or RunAs(), but I get a PID=0 and @error=1. Error codes are not explained in the help. Can someone help out?

TIA

--

Greetings from Germany!

Uwe

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi Doc,

can you show your code please?

Otherwise we can assume only what might be wrong.

PID=0 means the run command was not successfull.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

RUN() Return Value

Success: The PID of the process that was launched.

Failure: Returns 0 and sets @error to non-zero

Post the script

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Sorry guys,

I was more interested in WHAT error 1 means resp. where I can read that.

But here we go:

$Shl = "command /c"

$Cmd = "PGRestaWS"

$usr = "yyy"

$Domn = "xxx"

$Shw = @SW_MINIMIZE

$AsAdmin = 0

If $AsAdmin Then

$PID = RunAs($usr, $usr, $Domn, 4, $Shl&$Cmd, _

$Path, $Shw, 0x3) ; Call a console ; Call a console as admin

$MyError=@error

Else

$PID = Run($Shl&$Cmd, $Path, $Shw, 0x3) ; Call a console as user

$MyError=@error

EndIf

Share this post


Link to post
Share on other sites

Try this

$Shl = @ComSpec & " /c "
$Cmd = "PGRestaWS"
$usr = "yyy"
$Domn = "xxx"
$Shw = @SW_MINIMIZE
$AsAdmin = 0
$Path = ""

If $AsAdmin Then
    $PID = RunAs($usr, $usr, $Domn, 4, $Shl&$Cmd, _
      $Path, $Shw, 0x3)    ; Call a console                ; Call a console as admin
    $MyError=@error
Else
    $PID = Run($Shl&$Cmd, $Path, $Shw, 0x3)                ; Call a console as user
    $MyError=@error
EndIf

And please use code tags when posting the code ;)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

UEZ,

thx for your solution.

I assume RunAs() does really need the complete path to cmd; having cmd in the search path is not enough?!

Anyway, do you have a ref to the error codes as being returned by Run() and RunAs()?

I'll try my best with code tags in future. Had been away from here for looong time ;-)

Share this post


Link to post
Share on other sites

Googling for 'RunAs Error Code 1' returns a lot of links. At least a few made the impression that a fully qualified path is required as the help to RunAs() states.

--

Greetings from Germany!

Uwe

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Traskiz
      By Traskiz
      Hello,
       
      I have a problem, I cant run script as administrator in Windows 10:
      main.exe:
      RegWrite('HKLM\SOFTWARE\Policies\Microsoft\Windows\BITS', 'EnableBITSMaxBandwidth','REG_DWORD',Number('1'))
      RegWrite('HKLM\SOFTWARE\Policies\Microsoft\Windows\BITS', 'MaxTransferRateOnSchedule','REG_DWORD',Number('100'))
      RegWrite('HKLM\SOFTWARE\Policies\Microsoft\Windows\BITS', 'MaxBandwidthValidFrom','REG_DWORD',Number('7'))
      RegWrite('HKLM\SOFTWARE\Policies\Microsoft\Windows\BITS', 'MaxBandwidthValidTo','REG_DWORD',Number('22'))
      RegWrite('HKLM\SOFTWARE\Policies\Microsoft\Windows\BITS', 'UseSystemMaximum','REG_DWORD',Number('1'))
      RegWrite('HKLM\SOFTWARE\Policies\Microsoft\Windows\BITS', 'MaxTransferRateOffSchedule','REG_DWORD',Number('400'))
      run.exe:
      Global $sUserName = "administrator"
      Global $sPassword = "pass"
      Global $sDomain = "domain"
      RunAsWait($sUserName, $sDomain, $sPassword, 2, "main.exe", "", @TempDir)
      If I run "run.exe" it dont work...
      If  I change main.exe to this:
      msgbox(1,"",@username)        
      and it runs and shows administrator in message box... but it cant elevate main.exe with RegWrite() command...
       
      I tried using #RequireAdmin in first line of main.exe, but it not worked... UAC is set to "do not notify"
       
       
      This method of elevation worked on Windows 7 and Windows XP...
      Please help!
    • Surf243
      By Surf243
      Hello,
      I've been using this UDF to set ACL permissions to some network folders, everything works great (no issues). However, I want to apply these permissions using elevated domain credentials supplied by the user and not the user that's currently running the script. As a temporary solution, I've implemented a RunAs function, but that's not the solution I'm looking for. I'm not fluent with using Dlls, but I have been trying out different methods.
      My RunAs Function:
      Func _RunAs($sUser, $sPass) If @Compiled Then RunAs($sUser, @LogonDomain, $sPass, 4, FileGetShortName(@ScriptFullPath), "", @SW_MAXIMIZE) Else RunAs($sUser, @LogonDomain, $sPass, 4, FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath), "", @SW_MAXIMIZE) EndIf EndFunc ;==>_RunAs I tried LogonUser and I know that I can take that token to ImpersonateLoggedOnUser, but I'm not sure how to implement that or if that's even the right method. I also need to RevertToSelf once completed.
      Func _LogonUser($sUsername, $sPassword, $sServer = @LogonDomain) ; Returns True if user exists Local $stToken $stToken = DllStructCreate("int") Local $aRet = DllCall("advapi32.dll", "int", "LogonUser", _ "str", $sUsername, "str", $sServer, "str", $sPassword, "dword", 3, "dword", 0, "ptr", DllStructGetPtr($stToken)) ;$hToken = DllStructGetData($stToken, 1) If Not @error And $aRet[0] <> 0 Then Return True EndIf Return False EndFunc ;==>_LogonUser Any assistance, suggestions or idea's would be helpful.
      Thanks!
    • Milas
      By Milas
      Hey guys,
               for some reason when I run this command with run as in autoit it returns access is denied. but when I run the same thing in an elevated command shell it works fine. Im not sure where I am messing up.
      global $rtech,$rcred, $IP $rtech = inputbox("","username") $rcred = InputBox("","password") $ip = inputbox("","enter IP") $pid = Runas ($rtech,"mhs", $rcred, 2 ,@ComSpec & ' /c reg query \\' & $ip & '"\hklm\software\microsoft\windows\currentversion\group policy\state\machine"|findstr /i "disting"', @SystemDir, @SW_hide, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line &= StdoutRead($pid) If @error Then ExitLoop WEnd While 1 $line &= StderrRead($pid) If @error Then ExitLoop WEnd MsgBox(0, "", $line)  
    • WoodGrain
      By WoodGrain
      Hi All,
      I've got a script setup to drop a program into a temp folder and then run it from there, but I have mixed results, the Run() command will work on some computers but not others. The file will be placed into the temp folder in all cases. Running AutoIT 3.3.14.0. The computers are all either Win 7 or 8.1, x64 (exe is compiled to x64 too), UAC is off, all have local admin rights - if I've missed something ask and I'll update the details.
      If Not FileExists (@TempDir & "\HCTB") Then DirCreate(@TempDir & "\HCTB") FileInstall("G:\IT\Downloads\TB\12.0.45471\Host\TB_Setup-sif7r8pgcq.exe", @TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe", 1) Local $iPID = Run(@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe", "") Any suggestions?
      Thanks!
    • JRZJulien
      By JRZJulien
      Dears,
      i want add one recorder into HOSTS file file with following script in windows 7, but always failed, does anyone help me to correct it ?
      --script start--
      Local $sUserName = "Administrator"
      Local $sPassword = "abcd1234"
      RunAs($sUserName,@computername,$sPassword,0,"attrib -s -h -r C:\Windows\System32\drivers\etc\hosts")
      RunAs($sUserName,@computername,$sPassword,0,"echo xxx.xxx.xxx.xxx www.google.com" & @CRLF)
      RunAs($sUserName,@computername,$sPassword,0,"attrib +s +h +r C:\Windows\System32\drivers\etc\hosts")
      --script end--