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
Valuater

First... You have a Syntax error

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", "")
EndIf

I did not check further

 

8)


NEWHeader1.png

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

    • PINTO1927
      By PINTO1927
      HI GUYS,
      I'm trying to run this script with an advanced domain user, but when compiling the cmd it returns access denied, as if it did not recognize the user of AD.
       
      RunAsWait("administrator", "CONTOSO", "Services.1", 2, "C:\Users\albert.frizz\Desktop\test.bat")
       
      can you help me please?
    • rkr
      By rkr
      Hi, I have a software which has a 'run file'-ie; when i double click on that file, the input file of the software is run by the software. I wish to double click/execute this run file using autoit. how do i achieve this. i opened the software and it shows the input file and run file in same folder, i will put my autoitscript file too in same location. how do i simulate double clicking the run file (using its file name, say - abc.run ). I entered the following lines to make software window active - it became active, dont know how to go forward
      Winactivate("program title")
      winwaitactivate("program title")
      controlclick("program title","abc.run",1000,"primary",2) ; 1000 is ctrl id
    • SchneiMi
      By SchneiMi
      Hello,
      following my previous question, I have moved all potentially instable object interactions into Executes. But it Looks like "="-assignments to object Attributes cannot be done with Execute, only method calls. Using an "$obj = 1" construct, it compares (Eval) instead of sets (Execute) the value.
      I have tested multiple different combinations, using Execute and Assign, but it seems not to work with object Attributes. :-(
      Gives following Output:
      The assign Action using apply (a3) Fails, while assigning it directly, without Assign() works fine.
      The execute versions compare and do not assign, in both cases. Though, the "Execute" topic in the help file says it executes, not evaluates.
      I have found a similar, old thread, which explains this behavious but does not give a solution. https://www.autoitscript.com/forum/topic/110228-pass-object-property-as-a-variable/  
      Is there a way to assign to a com object's Attribute? Or is there anything new to this unexpected behaviour of Execute (at least compared to the help file description and Python's exec).
       
      Any help is appreciated, and thank you for all the help so far.
      Regards, Michael
       
    • tremolux66
      By tremolux66
      Initial Problem
      I've written several scripts with the following sequence:
      Execute a program using Run w/stdout+stderr captured Typically processes all the files in one directory tree to populate a second tree Execute a second program (also with Run) to monitor the products of the first program and Display a progress bar (percentage of output files complete) Also monitor the first program's process and exit when it terminates The script then calls ProcessWaitClose (no timeout) on the first program's process and Checks the first program's results Kills the monitor program if it hasn't already exited on its own. Sometimes, ProcessWaitClose returns 1 with @error = 0 and @extended = 0xCCCCCCCC (actually, 0xFFFFFFFFCCCCCCCC), which seems ambiguous: the documentation says that @error = non-zero and @extended = 0xCC... means an invalid PID (unclear what the return value is), and 1 is returned for non-existent processes (but no mention of @extended). The 1/0/0xCC... result seems to occur when the first program exits very quickly (with or without an error). Since the exit value is not available, the script scans the program's output and tries to determine whether it ran successfully. This has gotten complicated and unreliable.
      Partial Fix
      I've now implemented a much simpler approach that works for most cases:
      Modify the monitor program so that it ignores the other program's process (the monitor always gets killed by the script anyway) Execute the monitor program first using Run, then execute the processing program with RunWait When RunWait returns, the child process exit value is available, so the script can ignore its output (which isn't available anyway) If the monitor program is still running, kill it. Remaining Issue
      However, there are still a couple of cases where it's necessary to get both the exit value from the processing program and its output. Since RunWait doesn't capture stdout and stderr for the parent script, it's looking like I'll have to call RunWait and redirect the 2 streams to a temp file and then scan it. Also, to do the redirect, I think I'll have to use @ComSpec to execute the processing program, which adds an undesired layer.
      Does anybody have a better (cleaner) way to handle these cases?
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.