Reputation: 29925
I'm struggling to run a program from my VBScript .vbs file. Substituting the line for a MsgBox works fine, so I know its definitely the "open program" line (oShell.Run("Release\My Application.exe")
).
Anyway, this is a VBscript called start.vbs
which is run from the root directory of a USB drive. It checks to see if .net framework 4.0 is installed and if it is then it should run My Application.exe
(note the space... it might make a difference). My Application.exe
is in a folder called Release
.
As it is a USB drive I can't use explicit drive letters, eg: oShell.run("e:\Release\My Application.exe")
although trying this also doesn't appear to work. Typing "e:\Release\My Application.exe"
into a cmd window works fine, and runs the program as it is meant to work.
In the vbscript it just doesn't appear to do anything. Any reason?
Here is my code:
Option Explicit
Dim oShell
Dim value
On Error Resume Next
Set oShell = CreateObject("WScript.Shell")
value = oShell.RegRead("HKLM\SOFTWARE\Microsoft\.NETFramework\Policy\v4.0\30319")
If Err.Number = 0 Then
'Here I am struggling
oShell.Run("Release\My Application.exe")
Else
MsgBox("Version 4.0 of the .NET Framework is NOT installed.")
End If
I have commented above the line that doesn't work.
Thank you.
Upvotes: 0
Views: 657
Reputation: 1889
Not quite sure if this is the best answer, but I tried it and it work, so I'll just go ahead and post my idea. I just used explorer.exe as a mediator and was able to open the file. So the line that you're stuck with should probably become something like:
oShell.Run("explorer ""Release\My Application.exe""")
I tried it if it'll work in folder that is not in the System path and was able to open the executable.
Note : There may be better approaches.
Update: Thomas reported that the following code worked for him (the approach is better), the idea behind both approaches however is to quote the path (as you would do this in the Command Prompt, so filenames / folders with spaces in the path are properly resolved):
oShell.run("""Release\My Application.exe""")
Upvotes: 1