I am currently using the following code to run a dos command as follows from VBA.
Set objShell = CreateObject("WScript.Shell")
dos_command="\\\10.xx.xx.xx\test\7z.exe a -r " etc etc etc
result = objShell.Run(dos_command, 0, True)
Set objShell =nothing
All runs well, the only problem is that I get an annoying Warning Windows Box advising a program is trying to run in my computer, press OK or Cancel
I must use "objshell" because I need VBA to wait until DOS command is completed.
is there a way to avoid the warning box from coming up from within VBA or adding some additional parameters to the DOS command ?
The 7z.exe file is running in a server (not local PC) so I assume that’s the problem.
I cannot use or install 7z.exe in each machine.
Here are three options, presented in order from quickest/dirtiest to most robust:
Create a text file as part of command line and wait for its existence: modify your command line to something like this and run it using
Shell(not yourobjShell):This will create a text file named
TempFileNameafter your 7-zip code completes. You just need to make sureTempFileNamedoes not exist before you run your shell command, then run the command and wait for theTempFileNamefile to exist.Use
OpenProcessandGetExitCodeProcessAPIs: launch your command line using the OpenProcess API call which provides access to your new process (note that theShellfunction returns the ProcessID of the launched process). Then use the ProcessID to sit in a loop and poll the process via GetExitCodeProcess. Relevant declarations:Use CreateProcess and WaitForSingleObject APIs: refer to the “Super Shell” example at this help page for CreateProcess