Jump to content
WoodGrain

Run() executes on some computers but not others

Recommended Posts

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!

Edited by WoodGrain
Corrected syntax

Share this post


Link to post
Share on other sites
WoodGrain

Sorry, my bad, that EndIf should not have been there!

I've updated my original post with the correct syntax.

Share this post


Link to post
Share on other sites
Valuater

Somethings to consider.... I have had problems in the past with a longname..

 

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 $rFile = FileGetShortName(@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe")
Local $iPID = RunWait($rFile, @WorkingDir)

The runwait allows a little more time

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
WoodGrain

I've confirmed it is less than 100 characters using the temp dir, so this should be well clear of the 255 limit even if the user has a long username. Thanks for the reference to  FileGetShortName though, looks useful for other scripts I have.

I'll have a look at runwait. I've tried it with Sleep(10000) on a brand new i7 SSD system before calling Run(), so it's probably not time related. The next statement in my script is a WinWait() anyway.

It's like the Run() statement isn't actually executing on some systems, because even if I go and double-click on the exe in the temp dir the rest of the script doesn't continue to run. So it does the FileInstall(), I can go in to the file system and verify these files exist, then doesn't appear to execute the Run() because the subsequent line is WinWait() and even if I run the exe manually from the temp dir it doesn't progress as if it's still waiting for the Run() statement to complete. I know the syntax is correct for the WinWait because it does execute on some other computers.

Share this post


Link to post
Share on other sites
WoodGrain

I've had a look, I don't think I want to use RunWait(), I want to continue running the script before the installer instance will end.

Share this post


Link to post
Share on other sites
Valuater

Try the FileGetShortName()... I have had problems with less than 100 char's before.. AND maybe a small sleep before the Run() statement

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
francoiste

i would guess that on "some" of your computers the @TempDir have space characters in the path.
so for Run(...) make sure to embrace the path with quotes.

in addition: just add error handling wherever you can:

Local $sTargetPath = @TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe"

If Not FileExists (@TempDir & "\HCTB") Then
    If Not DirCreate(@TempDir & "\HCTB") Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Failed to create directory.")
    EndIf
EndIf

If FileExists ($sTargetPath) Then
    If Not FileSetAttrib($sTargetPath, "-R") Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Failed to remove read-only flag.")
    EndIf
EndIf

If Not FileInstall("G:\IT\Downloads\TB\12.0.45471\Host\TB_Setup-sif7r8pgcq.exe", $sTargetPath, 1) Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Failed to copy file.")
EndIf
Sleep (500)

If Not FileExists ($sTargetPath) Then
   MsgBox($MB_SYSTEMMODAL, "Error", "Target file does not exist: " & $sTargetPath)
EndIf
Local $iPID = Run( """" & $sTargetPath & """", "") ;# Paths with spaces need to be enclosed in quotation marks!
If $iPID = 0 Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Failed to spawn: " & $sTargetPath)
EndIf

 

Edited by francoiste

Share this post


Link to post
Share on other sites
WoodGrain

Thanks, these paths should not have any spaces, none of the usernames we create have spaces in them and the path to the temp folder doesn't have any spaces. I checked the laptop I ran this on yesterday and confirm the path has no spaces (C:\Users\jbloggs\AppData\Local\Temp\\HCTB\TB_Setup-sif7r8pgcq.exe) and is also less than 100 characters in length.

I note that when I display the $iPID result to a msgbox:

MsgBox(0, "iPID", $iPID)
MsgBox(0, "Error Code", @error)

I get the result 0 and an @error code of 0. I'm not sure if I am using @error correctly, I've not used it before.

Share this post


Link to post
Share on other sites
JohnOne
MsgBox(0, "iPID", $iPID)
MsgBox(0, "Error Code", @error)

@error there gives you result from MsgBox above it, try...

$err = @error
MsgBox(0, "iPID", $iPID)
MsgBox(0, "Error Code", $err)

Or

MsgBox(0, "Error: " & @error, $iPID)

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
WoodGrain

I'm afraid I've had to deploy this laptop, I'll see if I can find another box that is having the same issue.

$iPID is returning 0 which according to the documentation is an error, so now I just need another box to find out what the error code is to give some direction I guess.

Share this post


Link to post
Share on other sites
WoodGrain

Ok, so I found another machine that has this issue, I ran your code and got the 2 message box results: 0 and then 1.

$err = @error
MsgBox(0, "iPID", $iPID)
MsgBox(0, "Error Code", $err)

I'm not sure this means anything apart from it failed to run?

PS, I also tried enclosing it in quotes per the above suggestions and it had the same issue.

I manually copied the exe into a folder "C:\Test" to see if I could run it from there and got the same result (wouldn't start and returned 0 and then 1 in the message boxes. I trimmed my script so it only tried Run() and returned message boxes per the above error code, this ensures it's not a spaces issue or a file path length issue and that there are no temp folder permissions/restrictions causing issues if they exist.

This is another wiped and reinstalled machine with nothing on it apart from Windows and all Windows Updates.

It wouldn't bother me if this didn't work on any of the machines, that would at least indicate a problem with my script. But this 50/50 working is driving me insane.

Share this post


Link to post
Share on other sites
GordonFreeman

Cannot do it with ShellExecute (or ShellExecuteWait) function?

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 = ShellExecute(@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe")

 

Share this post


Link to post
Share on other sites
francoiste

@WoodGrain:

1) the code snippet in post #9 has some additional error checking.
so what is the output on your problem machines? which of the messageboxes are showing up?

2) as suggested by JohnOne in post #2: do you see different behaviour when explicitly requesting admin privileges?
add the following line at the top of your script:

#RequireAdmin

 

to get assistance with your issue you should be more responsive ...

Edited by francoiste

Share this post


Link to post
Share on other sites
WoodGrain

@francoiste Thanks for your follow up, sorry to keep you waiting.

Regarding your questions I'll try and answer them as best I can, hopefully I can cover everything, let me know if I've missed something:

  • The folder in the temp dir (HCTB) is created every time, with no exceptions.
  • The read only attirbute isn't the cause as I can execute the file manually by double-clicking it and it will start up successfully.
  • The exe (TB_Setup-sif7r8pgcq.exe) is successfully extracted every time, with no exceptions.
  • It is at this point that it appears that the Run() statement isn't executing on all machines. Either the Run() command will work and the setup exe will run or nothing happens on the machine with no errors.
  • Per post #13 $iPID = 0
  • Per post #13 I tried with quotes with the same result.
  • Per post #13 all users are administrators and the setup exe doesn't need to be installed via right-click - Run as administrator, it can just be executed by double-clicking the setup exe, so I assume I don't need to include the #RequireAdmin? Thanks for clarifying this point though :) I was unfamiliar with #RequireAdmin before.

Let me know if I can clarify anything else ^_^

Share this post


Link to post
Share on other sites
WoodGrain

@GordonFreeman, is there a particular reason I should be using ShellExecute() instead of Run()? From what I can see Run() is exactly what I need to start the program. Actually, I'm hoping you can explain the difference to me lol as I'm not 100% on the difference? I tried this google search (https://www.google.com.au/search?q=autoit+difference+between+run+and+shellexecute) but couldn't find much, and looking at the AutoIt help file only seems to indicate that ShellExecute() is using an API and can open files based on their extension (like .txt etc), though the help file is not specific as to how Run() calls the file? Apologies as I'm a scripter rather than a programmer so some of this is a bit foreign to me.

I've had to deploy the computer for post # 13, but I can try ShellExecute() on the next one I can get my hands on where Run() doesn't work.

Share this post


Link to post
Share on other sites
WoodGrain

Hmm, could Windows SmartScreen be interfering with extracting and running an exe using Run() as discussed here?

Share this post


Link to post
Share on other sites
PACaleala

Windows SmartScreen blocks execution of files (Installer) from "unverified publishers".

 

Share this post


Link to post
Share on other sites
VIP

That's the warning a program run with administrator privileges required and unverified publishers.
 

#RequireAdmin

Do 
    DirCreate(@TempDir & "\HCTB\")
Until FileExists(@TempDir & "\HCTB\")

Do
FileInstall("TB_Setup-sif7r8pgcq.exe",@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe",1)
Until FileExists(@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe")

Local $iPID = Run(@TempDir & "\HCTB\TB_Setup-sif7r8pgcq.exe", "")

 

 

The only way to do this is to obtain and use a code signing certificate from a trusted source. Microsoft calls this Authenticode.

Unfortunately for the little guy, these cost. Verisign sells theirs for about four hundie a year.

Here are some starting points you should read about Authenticode:

http://msdn.microsoft.com/en-us/library/ms537359%28VS.85%29.aspx
http://technet.microsoft.com/en-us/library/cc750035.aspx
http://msdn.microsoft.com/en-us/library/aa379872%28VS.85%29.aspx

Some certificate dealers:

http://www.verisign.com
http://www.thawte.com
http://www.globalsign.net
http://www.geotrust.com


Regards,
 

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

  • Similar Content

    • AnonymousX
      By AnonymousX
      So I just got a new computer, and instantly went and installed Autoit onto it. I selected run script as default action when clicking on an au3 file, however every time I do this it opens the script in the editor. I can from there run the script no problem.
      I've tried reinstalling and checking the settings by hitting "Ctrl+1" and have confirmed it is set to run, but yet it just continues to open in the editor.
      Any ideas why this is happening or how to solve?
      New system is windows 10, old was windows 7
    • SanCon
      By SanCon
      Greetings,
      I've found and used @TheDcoder's ProcessEX UDF, and have found it and invaluable tool in my scripting arsenal. Recently, I found myself needing to create a script which then attempts to run another program as a different user. I was able to heavily borrow from the _Process_RunCommand function to create _Process_RunAsCommand:
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Process_RunAsCommand ; Description ...: Runs a command or an executable under a different user security privilege. ; Syntax ........: _Process_RunAsCommand($iMode, $sUserName, $sUserPass, $sUserDomain, $sExecutable [, $sWorkingDir = @TempDir [, $iRunOptFlag = $STDERR_MERGED]]) ; Parameters ....: $iMode - Mode in which this function should operate, See Remarks. ; $sUserName - User name under which you would like to run the command/executable. ; $sUserPass - Password for $sUserName. ; $sUserDomain - Domain name to which the $sUserName belongs. ; $sExecutable - The command to run/execute (along with any arguments). ; $sWorkingDir - [optional] The working directroy for the command. Default is @TempDir. $sUserName must have ; privileges to create/modify files on this directory. ; $iRunOptFlag - [optional] The Opt flag for the Run function. Default is $STDERR_MERGED. ; Return values .: Success: Mode $PROCESS_RUN : Will return the process handle & @extended will contain the PID of the command ; Mode $PROCESS_RUNWAIT : Will return the output & @extended will contain the exit code for the function ; Failure: Will return False & @error will contain: ; 1 - If the $iMode flag is invalid ; 2 - If the command is invalid ; Author ........: J. Sanchez, heavily borrowing from code by TheDcoder ; Modified ......: N/A ; Remarks .......: 1. The ONLY valid modes are: $PROCESS_RUN & $PROCESS_RUNWAIT ; $PROCESS_RUN : Will act similarly to Run function, See Return values ; $PROCESS_RUNWAIT : Will act similarly to RunWait function, See Return values ; If you use $PROCESS_RUN then use _Process_GetExitCode to get the exit code & use StdoutRead to get the output of the command ; 2. Use $PROCESS_COMMAND to run commands like this: $PROCESS_COMMAND & "ping 127.0.0.1" ; 3. Add $PROCESS_DEBUG to $iMode to automagically debug the command, $PROCESS_RUN is equivalent to $PROCESS_RUNWAIT in this case ; Related .......: RunAs, RunWait ; Link ..........: http://bit.ly/ProcessUdfForAutoIt ; Example .......: Yes, see example.au3 ; ===============================================================================================================================; Functions Func _Process_RunAsCommand($iMode, $sUserName, $sUserPass, $sUserDomain, $sExecutable, $sWorkingDir = @TempDir, $iRunOptFlag = $STDERR_MERGED) Local $iExitCode = 0 ; Declare the exit code variable before hand Local $sOutput = "" ; Declare the output variable before hand Local $bDebug = False ; Declare the debug variable before hand If BitAND($iMode, $PROCESS_DEBUG) Then $bDebug = True If BitAND($iMode, $PROCESS_RUN) Then $iMode = $PROCESS_RUN ElseIf BitAND($iMode, $PROCESS_RUNWAIT) Then $iMode = $PROCESS_RUNWAIT Else Return SetError(1, 0, False) EndIf ; If Not $iMode = $PROCESS_RUN Or Not $iMode = $PROCESS_RUNWAIT Then Return SetError(1, 0, False) ; If the mode is invalid... ;Local $iPID = Run($sExecutable, $sWorkingDir, @SW_HIDE, $iRunOptFlag) ; Run!!! :P Local $iPID = RunAs($sUserName,$sUserDomain,$sUserPass,BitAND(0,4),$PROCESS_COMMAND & " " & $sExecutable,$sWorkingDir,@SW_HIDE,$iRunOptFlag) If @error Then Return SetError(2, @error, False) ; If the command is invalid... Local $hProcessHandle = _Process_GetHandle($iPID) ; Get the handle of the process If $iMode = $PROCESS_RUN Then If Not $bDebug Then Return SetExtended($iPID, $hProcessHandle) ; If the function is in Run mode then return the PID & Process Handle $sOutput = _Process_DebugRunCommand($hProcessHandle, $iPID) ; Debug the process $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code Return SetExtended($iExitCode, $sOutput) ; Return the output & exit code EndIf If Not $bDebug Then While ProcessExists($iPID) $sOutput &= StdoutRead($iPID) ; Capture the output Sleep(250) ; Don't kill the CPU WEnd $sOutput &= StdoutRead($iPID) ; Capture any remaining output $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code Return SetExtended($iExitCode, $sOutput) ; Return the exit code & the output :D EndIf $sOutput = _Process_DebugRunCommand($hProcessHandle, $iPID) ; Debug the process $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code Return SetExtended($iExitCode, $sOutput) ; Return the output & exit code EndFunc The issue that I currently have is that, regardless of what the errorlevel returned by the program being executed, the errorlevel returned by the _Process_RunAsCommand is 259, which, according to this page it means that there's no more data (I'm guessing from the STDIO and STDERR?)
      Any guidance would be greatly appreciated.
    • damon
      By damon
      Hello,
      You guys helped me years ago to address logging in with a different account than the user.  I have sense modified it over the years due to laptops syncing with AD which is why you will see 3 different passwords.  So, this script snippet has worked for me in many things i have written but I am all the sudden having an issue getting it to work.  I have verified that the password i am using for the local user account is $pass.  Verified by doing a run as different user on Chrome and cut and pasted the password out of the script just to make sure i was not fat fingering something.  
      I get a fail back from RunAs every time.   
      Any chance you guys see something i am doing wrong?
       
      #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> ;#RequireAdmin If $CmdLine[0] > 0 Then If $CmdLine[1] = "/Install" Then RunUpdate() Exit EndIf ;;Will check users account to determine if admin, if not will Run with admin rights -------------------------------------------------------------- ;;Varables Start Local $user = ".\user" Local $pass = "password1" Local $pass2 = "password2" Local $pass3 = "password3" Local $filetorun = @ScriptFullPath & " /Install" ;;Varables End If IsAdmin () = 0 Then If RunAs ( $user, @CompterName, $pass, $RUN_LOGON_NOPROFILE,$filetorun) = 0 Then ;If RunAs ( $user, @ComputerName, $pass2, 0,$filetorun) = 0 Then ;If RunAs ( $user, @ComputerName, $pass3, 0,$filetorun) = 0 Then ;MsgBox (0,"Installation Error", "This installation was interrupted due to an incorrect Admin Password") ;Exit ;EndIf ;EndIf EndIf Exit Else Run ($filetorun) EndIf Func RunUpdate() MsgBox(0,"worked","worked") EndFunc
    • HariKara
      By HariKara
      Hi AutoIters!
       
      Im trying to launch a .exe file that is nested within the program files (x86) folder structure. i have already used the standard RunAs Syntax and found that it fails to launch the application. I have switched to Run and that seems to work. My issue is I have to use RunAs as the applicaton would need to run under a completely different account. The Current logged in user is a Local User on the machine, however, the application must be run as a domain user. The Machine is domain connected.
       
       have tried the following:
      RunAs("username","logonpassword", $RUN_LOGON_PROFILE, "D:\Program Files (x86)\Vendor\Application Name\Exe Location\Executable.exe") The above fails to launch, there are no errors or syntax issues, it just does nothing when the variables are replaced for the correct values.
      I did the same using the Run command
      Run("D:\Program Files (x86)\Vendor\Application Name\Exe Location\Executable.exe") That seems to work fine, but runs in local user context. Any thoughts? Could it be a local Machine rights issue? Or have i missed something glaring in my script
×