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!
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)
Please log in to answer
Posted by:
Meic
16 years ago
Posted by:
anonymous_9363
16 years ago
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.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.