我在VBScript
中找不到任何替换%~dp0的内容On error resume next
Set shell= createobject("WSCRIPT.SHELL")
Shell.run "%~dp0test.bat", vbhide
答案 0 :(得分:3)
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheParent = fso.GetParentFolderName(Wscript.ScriptFullName)
从这里采取:
要在脚本中使用获取的值,请添加对需要其值的变量的引用。例如:
Shell.run GetTheParent & "\test.bat", vbhide
答案 1 :(得分:0)
要获取执行.VBS所在的文件夹:
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
答案 2 :(得分:-1)
这应该有用。
set objShell = Createobject("wscript.shell")
strPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
Shell.run strPath & "test.bat", vbhide