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

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


“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

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

    • nss
      By nss
      Hi all. I am creating an app that runs a program with the admin privileges using the shellexecute's run as verb, but what my problem is, that no matter what I use to launch the program, it doesn't quite work like the run dialog would (certain programs don't get found, etc.). I've tried using the explorer.exe and passing the program to it, that is unreliable and opens documents folder sometimes instead, I've tried using the @comspec /c and that works better, but still some of the programs aren't being found that would be with the run dialog e.g., if I do @comspec /c diskpart it won't find it, I've even tried setting the working dir, but still no luck. I also tried passing commandline params to C:\WINDOWS\system32\rundll32.exe shell32.dll,#61, but no luck. can anyone help me what way to go in order to be able to launch programs in the run dialog style? is there a function in winapi that run dialog uses that I could use as well? Or what would be the best way to go about this? Any help much appreciated.
    • Skysnake
      By Skysnake
      I need help.
      I have a project that outputs reports to PDF using @mLipok's lovely QuickPDF.  The PDF is created with no problem and I am sure the problem is not there.
      However, I then have to open the PDF so the user can see it.
      I use (a) short file name and (b) object properties
      $oQP.SetPageLayout(2) $oQP.SetPageMode(3) ... $sFilename ; as created by UDF Local $sShortname = FileGetShortname( sFilename , 1 ) Run( @ComSpec & " /c start /max " & sShortname, "", @SW_HIDE ) ; force default PDF reader to open PDF maximized Then the RUN should open it with the default application.
      I have tested extensively on 32 bit Win7 and 64 bit Win10.  Works.
      However, 64 bit Win8 and another Win7 laptop gives a problem.
      The problem is this: when (typically) Adobe Reader is ALREADY open, the PDF opens almost instantaneously.  If the Reader is not open, it seems to stall.  Never opens.
      The host on which the report will be opened is unknown to me and the PDF reader can not be hard coded.
      Right now, my only brutal, very un-stylish solution is to force the Reader open prior to the RUN command.
      Any ideas or advice on what causes this or how it could be remedied would be greatly appreciated.
      Anything, please.
      -Skysnake
    • Vivaed
      By Vivaed
      Trying to automate the sideload of a Windows Store app via .ps1 script...
      RunWait(@ComSpec & ' /c' & 'C:\"WB Resources"\APP_Prod\Add-AppDevPackage.ps1') Above doesn't work... I assume this is trying to open in CMD.
       
      Normally we right click the .ps1 and open with powershell, then we have to type "A" to start the install, it installs and then type any yet to exit.
      However I cant get the powershell to even open.
      Kind of puzzled here, any suggestions would be a help.
      PS I also tried to convert the .ps1 to exe, but that was a huge failure... lol
    • 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!