/build/static/layout/Breadcrumb_cap_w.png

Specifying Directory when launching file in VBS

Hi,

From a VBScript, I am trying to launch an exe that's in C:\Program Files\Form\Test.exe.

If I use the following code, I get "The system cannot find the file specified." Code - 80070002.

Set oShell = CreateObject("WScript.Shell")
oShell.Run "c:\Program Files\UserForm\Test.exe"

If I put the file in c:\windows, and change the following line, it works.

oShell.Run "c:\Program Files\UserForm\Test.exe"

to

oShell.Run "c:\Windows\Test.exe"

How do i set the path, and then get it to run the file in the correct location?

Thanks!

0 Comments   [ + ] Show comments

Answers (5)

Posted by: turbokitty 16 years ago
6th Degree Black Belt
0
Try

oShell.Run "c:\Progra~1\UserForm\Test.exe"
Posted by: AngelD 16 years ago
Red Belt
0
or try
oShell.Run """c:\Program Files\UserForm\Test.exe"""
Posted by: Meic 16 years ago
Second Degree Blue Belt
0
Thanks for your replies - using Program~1 instead of Program Files worked.

Cheers.
Posted by: anonymous_9363 16 years ago
Red Belt
0
Thanks for your replies - using Program~1 instead of Program Files worked.Ever heard of defensive programming? Your code now assumes that a) the 'Program Files' folder is on the C: drive and b) that its short name will always be 'PROGRA~1'. In 99.99% of cases, both of these assumptions will be true but not always.

Interrogate the registry (or less optimally, the environment variable 'ProgramFiles') to divine the actual location of the 'Program Files' folder. Then either wrap the command line in quotes or, if you want the short name, use FileSystemObject's ShortPath property.
Posted by: Meic 16 years ago
Second Degree Blue Belt
0
Thanks for your comments - will look into this...
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ