0
votes

There is a VBS file in a folder and it uses the command below for launching an application:

WshShell.Run ".\Setup.exe"

lets name the vbs file to "Run.vbs" Now If I Create a batch script and put it in the same path it will work good:

WScript Run.vbs

But If I came back just one folder and then try to launch the vbs file, it will give me an error that the specific file not found:

WScript Setups\Run.vbs

So it means Run.vbs file can not execute WshShell.Run ".\Setup.exe" because it seems it is running from another location! Even If I make the path correct and full (like the below command) it will not work via the batch file!

 WshShell.Run "C:\Folder\Setup.exe"

Where is the problem?

I even to try to fix the vbscript with the code below, but still it is not working if I launch it via batch script from another folder:

Set WshShell = WScript.CreateObject("WScript.Shell")
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
dim CurrentDirectory
CurrentDirectory = fso.GetAbsolutePathName(".")
dim Directory
Directory = CurrentDirectory & "\Setup.exe"
WshShell.Run Chr(34) & Directory & Chr(34)
1

1 Answers

3
votes

Check the value of WshShell.CurrentDirectory in your script. You can set this to whatever you'd like prior to calling WshShell.Run. The Shell object uses the CurrentDirectory property to deal with relative paths.

Update:

I'm getting confused by your folder hierarchy. Here's another way that doesn't rely on relative paths.

' Here's the folder where your script is at...
strScriptFolder = fso.GetParentFolderName(WScript.ScriptFullName)

' Here's its parent folder...
strParentFolder = fso.GetParentFolderName(strScriptFolder)

' Here's how you can run setup.exe in the script folder...
WshShell.Run Chr(34) & strScriptFolder & "\setup.exe" & Chr(34)

' Here's how you can run setup.exe in the script's parent folder...
WshShell.Run Chr(34) & strParentFolder & "\setup.exe" & Chr(34)