Reputation: 339
I can't find anything to replace %~dp0 in my VBScript
On error resume next
Set shell= createobject("WSCRIPT.SHELL")
Shell.run "%~dp0test.bat", vbhide
Upvotes: 5
Views: 5046
Reputation: 11
This should work.
set objShell = Createobject("wscript.shell")
strPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
Shell.run strPath & "test.bat", vbhide
Upvotes: 0
Reputation: 77707
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheParent = fso.GetParentFolderName(Wscript.ScriptFullName)
Taken from here:
To use the obtained value in your script, add a reference to the variable where you need its value. For instance:
Shell.run GetTheParent & "\test.bat", vbhide
Upvotes: 5
Reputation: 38755
To get the folder the executing .VBS resides in:
type dp0.vbs
Option Explicit
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
WScript.Echo "WScript.ScriptFullName", WScript.ScriptFullName
WScript.Echo "oFS.GetParentFolderName(WScript.ScriptFullName)", oFS.GetParentFolderName(WScript.ScriptFullName
)
cscript dp0.vbs
WScript.ScriptFullName E:\trials\SoTrials\answers\tools\jscript\ijs\dp0.vbs
oFS.GetParentFolderName(WScript.ScriptFullName) E:\trials\SoTrials\answers\tools\jscript\ijs
Upvotes: 0