Jump to content

Run() executes on some computers but not others


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

@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 ^_^

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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,
 

Link to comment
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
 Share

×
×
  • Create New...