Jump to content

Run exe-file with arguments


ahlm
 Share

Recommended Posts

Hello,

I'm new in the world of Autoit and have a questen about the Run-Command:

I have to write a program to "delay" the start of programs in the StartUp-folder as long as the pc has no connection to the network. My problem is that the first program starts with no difficulties, but that's it. The other two programs don't start and I dont't get an error-message. I tried to write the program in C# before, but got an error-message that the file couldn't be found. The name and the path are both correct so i don't know why i get this message.

Here is my current code:

#include<Inet.au3>
#include<MsgBoxConstants.au3>

$ip = @IPAddress1
While $ip = "127.0.0.1"
    MsgBox(0, "IP-Adresse", "Client not connected to the network yet")
    $ip = @IPAddress1
WEnd
If $ip <> "127.0.0.1" Then
    Run("C:\Program Files\HOBLinkTE\hoblinkl.exe")
    Run('"C:\Windows\System32\Empirum\EmpInventory.exe" "/CEmpInvScan_Windows.xml" "/O%Domainname%.%ComputerName%_%SysTime%.xml" /E /V2 /M /T /ZIP')
;~     Run("Desktop - Germany – Prod.exe.lnk","C:\Program Files (x86)\Citrix\ICA Client\SelfServicePlugin")
EndIf

 

Does anyone know how to fix this issue?

Thanks in advance.

ahlm

Link to comment
Share on other sites

If you want to use environment variables in strings, you need to add this line :

Opt ("ExpandEnvStrings", 1)

You could also use the different macros available in AutoIt (e.g. @LogonDomain, @ComputerName, etc.) instead of relying on environment vars.

In all cases, make sure you check for success or failure (@error) after each statement, so you know what kind of error you're having.

When posting code, please use this tool.

Edited by Nine
Link to comment
Share on other sites

I did a check after

Run('"C:\Windows\System32\Empirum\EmpInventory.exe" "/CEmpInvScan_Windows.xml" "/O%Domainname%.%ComputerName%_%SysTime%.xml" /E /V2 /M /T /ZIP')

and got the error code "1" back.

What does this mean? Is it the same problem as with my C# program, that the exe could not be found?

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/functions/Run.htm

Return Value

Success: the PID of the process that was launched.
Failure: 0 and sets the @error flag to non-zero.

 

look, you have to read the documentation, check the @error flag to see if any errors after operation. 

make sure your command runs on the command line properly first so you can get the syntax right

 

you can pm me your c# code, i will have a look at that.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Hmmm. You might need to set the working directory of the run command.

You can check before run :

if FileExists ("C:\Windows\System32\Empirum\EmpInventory.exe") then ConsoleWrite ("EXE is OK" & @CRLF)

If it is ok, then it is the parameters that cause the problem. 

Link to comment
Share on other sites

Are you running your script as 32 or 64 bit?  If you are running it as 32 bit, redirection could be your issue.  Also, if %SysTime% returns colons, they are invalid characters in a file name.  Based on your given code, give this a try.  

#include<MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

;Turn off redirection for a 32-bit script on 64-bit system.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

$ip = @IPAddress1
While $ip = "127.0.0.1"
    MsgBox($MB_OK, "IP-Adresse", "Client not connected to the network yet")
    $ip = @IPAddress1
WEnd
If $ip <> "127.0.0.1" Then  
    Run("C:\Program Files\HOBLinkTE\hoblinkl.exe")
    Run('"C:\Windows\System32\Empirum\EmpInventory.exe" "/CEmpInvScan_Windows.xml" "/O' & @LogonDomain & '.' & @ComputerName & '_' & @HOUR & @MIN & @SEC & '.xml" /E /V2 /M /T /ZIP')
EndIf

 

Adam

 

Link to comment
Share on other sites

Try :

;~ #RequireAdmin

ConsoleWrite ("> ==> @SystemDir = " & @SystemDir & @CRLF)

If FileExists (@SystemDir & "\Empirum\EmpInventory.exe") Then
    ConsoleWrite ("+ EmpInventory.exe found" & @CRLF)
Else
    ConsoleWrite ("! EmpInventory.exe not found" & @CRLF)
EndIf

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

21 minutes ago, Nine said:

Try #RequireAdmin at the beginning of your script.

I tried.. file still does not exist

I'm currently checking the files in C:\Windows\System32\Empirum\..

#include <MsgBoxConstants.au3>
#RequireAdmin

If FileExists("C:\Windows\System32\Empirum\lang") Then
    MsgBox(0,"", "Path exists.")
Else
    MsgBox(0,"", "Path does not exist.")
EndIf

"Lang" is another folder in the directory but even this folder does not exist.

Link to comment
Share on other sites

7 minutes ago, AdamUL said:

Are you running your script as 32 or 64 bit?  If you are running it as 32 bit, redirection could be your issue.  Also, if %SysTime% returns colons, they are invalid characters in a file name.  Based on your given code, give this a try.  

#include<MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

;Turn off redirection for a 32-bit script on 64-bit system.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

$ip = @IPAddress1
While $ip = "127.0.0.1"
    MsgBox($MB_OK, "IP-Adresse", "Client not connected to the network yet")
    $ip = @IPAddress1
WEnd
If $ip <> "127.0.0.1" Then  
    Run("C:\Program Files\HOBLinkTE\hoblinkl.exe")
    Run('"C:\Windows\System32\Empirum\EmpInventory.exe" "/CEmpInvScan_Windows.xml" "/O' & @LogonDomain & '.' & @ComputerName & '_' & @HOUR & @MIN & @SEC & '.xml" /E /V2 /M /T /ZIP')
EndIf

 

Adam

 

It worked!

Thank you all very much for your help. Espacally you especially Adam! 😊

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...