Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
petgr138
Partner - Contributor III
Partner - Contributor III

WScript.shell execution stops at Run command

Hello,

I'm trying to write a macro that executes an external program that creates an excel file which I want to load into my qlikview application.
I have tried using the WScript.Shell.Execute command to do this and it seems to work, however the external program is prone to some delay which causes the loading to fail sometimes.
I would like to use the WScript.Shell.Run command instead which has the built in functionality of waiting for a return value, i.e:


set WsShell = CreateObject("WScript.Shell")

WsShell.Run <Path to external exe-file>,1,true

However when trying to execute the macro the execution always stops at the WsShell.Run line with no error message.

Is there any solution to this problem?

Best regards

Petter Grundström

1 Solution

Accepted Solutions
marcus_sommer

The path respectively the complete statement must be in double-quotes wrapped. The correct syntax is really difficult and I couldn't never memorize it ... so I use most often trial and error ...

- Marcus

View solution in original post

12 Replies
marcus_sommer

Most often the path isn't correct especially if there are any whitespace in, here an example:

set objWscript = CreateObject("WScript.Shell")

pdf = """C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"""

objWscript.Run(pdf & """" & path & file & """")

Further it could be a lack of access rights within the filesystem for the user-account or the modul-security (left side of editor-window) isn't on external execution or user-settings within tab security isn't set.

- Marcus

petgr138
Partner - Contributor III
Partner - Contributor III
Author

Hi, thanks for your reply,

So, do I need to replace the whitespaces in the command path with "\ "?

The command path contains arguments to the exe-file as well i.e:

commandPath = "C:\Users\Petter\externalExe.exe\ argument1\ argument2\ argument3"

set WsShell = CreateObject("WScript.Shell")

WsShell.Run commandPath,1,true

//Petter

marcus_sommer

No - not replacing the whitespace else wrapped in with double-quotes:

""""Path\File"""" will be interpreted from compiler as "Path/File" (it's just syntax)

- Marcus

petgr138
Partner - Contributor III
Partner - Contributor III
Author

Hi,

I don't get it. This is the command I want to send:

C:\Users\Petter\executable.exe argument1 argument2 argument3

How should I write it for WsShell.Run to work?

Thanks for your help so far!

//Petter

marcus_sommer

I assume that your parameters caused this issue - have a look on this example:

running exe from vbscript and passing parameters

- Marcus

petgr138
Partner - Contributor III
Partner - Contributor III
Author

Well all that thread says is that I should write:
Set sh = CreateObject("WScript.Shell")
sh
.Run "C:\Users\Petter\executable.exe argument1 argument2 argument3", 0, True


Which is exactly what I tried in the first place but the execution always stops at that line


Did you get this to work?

//Petter

marcus_sommer

Perhaps one of these parameters aren't valid for your exe - have you tried it without these parameters.

- Marcus

petgr138
Partner - Contributor III
Partner - Contributor III
Author

They are valid. I have written the exe myself and it works fine if i run it from command line with the exact same input, it also works if I run:
CreateObject("WScript.Shell").Exec( "C:\Users\Petter\executable.exe argument1 argument2 argument3")

But since Exec() doesn't have any functionality for waiting for a reply from the execution it doesn't fulfill my needs.

Do you have a working example of VBS code where you use WsShell.Run with parameters?

//Petter

marcus_sommer

This runs and set a new variable-value:

set objWscript = CreateObject("WScript.Shell")

objWscript.run "D:\QlikView_Client\qv.exe /vupdate=1 D:\MyApp.qvw"

- Marcus