WoodGrain

Run() executes on some computers but not others

24 posts in this topic

#1 ·  Posted (edited)

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



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

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

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

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

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

#9 ·  Posted (edited)

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

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

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

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

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

#15 ·  Posted (edited)

@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

@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

@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

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

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

 

Share this post


Link to post
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,
 

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

    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
      Brian
    • ur
      By ur
      My profile when I logged in to a machine, it is showing @TempDir to C:\Users\uday\AppData\Local\Temp\2 instead of C:\Users\uday\AppData\Local\Temp
      But I need to delete a file in C:\Users\uday\AppData\Local\Temp folder.
      So I kept the target as @LocalAppDataDir & "\temp"
      It is expanding the value correctly and I confirm from messagebox also.
      But the code is stopping at that line and I am not getting any error also, it is simply stopping the execution there.
      Even I kept #RequireAdmin , but still same issue.
      Any suggestions?
    • rootx
      By rootx
      I need help to understand why the run function does not work, but if i use it directly inside cmd shell the command works. $where is the name of the jpg file
      ShellExecute(@ComSpec ," /k C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&'"'&$where&'"'&" > "&'"'&@ScriptDir&"\out.txt"&'"',@ScriptDir);<----- work Run("C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&$where&" > "&@ScriptDir&"\out.txt",@ScriptDir);<--- doesn't work I would use the run command!
      Thx
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it
    • kawliga751
      By kawliga751
      I am attempting to run an Autoit.exe with schtasks every weekday @ 9:05 am.
      I have the below
      C:\>SchTasks /Create /TN "P10Run" /TR "O:\AUTOIT\P40 Run.au3" /SC WEEKLY /D MON, TUE,WED,THU,FRI /ST 09:05:00 SUCCESS: The scheduled task "P10Run" has successfully been created. I also did a "test" run :
      C:\>Schtasks /Run /TN "P10Run SUCCESS: Attempted to run the scheduled task "P10Run". But when I run my query to verify success my "Last Result" seems to indicate that the script did not run:
      C:\>SCHTASKS /QUERY /FO LIST /V /TN "P10RUN" Folder: \ HostName: xxxxxxxxxxxxxxxx TaskName: \P10RUN Next Run Time: N/A Status: Could not start Logon Mode: Interactive only Last Run Time: 6/14/2017 9:08:56 AM Last Result: -2147024894 Author: xxxxxxx Task To Run: O:\AUTOIT\P40 Run.au3 Start In: N/A Comment: N/A Scheduled Task State: Enabled Idle Time: Disabled Power Management: Stop On Battery Mode, No Start On Batterie s Run As User: xxxxxxxxx\xxxxxxxx Delete Task If Not Rescheduled: Enabled Stop Task If Runs X Hours and X Mins: 72:00:00 Schedule: Scheduling data is not available in this f ormat. Schedule Type: Weekly Start Time: 9:05:00 AM Start Date: 6/14/2017 End Date: N/A Days: MON, TUE, WED, THU, FRI Months: Every 1 week(s) Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled C:\> Is there something missing in my command? Also is there a better way to make sure that the script does in fact sun successfully?
      Thanks In Advance!