4

我在我的 VBScript 中找不到任何东西来替换 %~dp0

On error resume next
Set shell= createobject("WSCRIPT.SHELL")
Shell.run "%~dp0test.bat", vbhide
4

3 回答 3

4
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheParent = fso.GetParentFolderName(Wscript.ScriptFullName)

取自这里:

要在脚本中使用获得的值,请在需要其值的地方添加对变量的引用。例如:

Shell.run GetTheParent & "\test.bat", vbhide
于 2013-02-03T21:04:00.373 回答
0

这应该有效。

   set objShell = Createobject("wscript.shell")
    strPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
    Shell.run strPath & "test.bat", vbhide
于 2014-02-24T10:45:58.077 回答
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
于 2013-02-03T21:09:56.237 回答