[英]Running an exe file with parameters in a VBScript
我需要從腳本所在的文件夾中創建一個運行setup.exe /configure Install.xml
的腳本。
當我運行下面的腳本時,它確實找到了setup.exe
,但未讀取參數。 就像沒有讀取最后一部分( /configure Install.xml
)。
腳本:
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
strPath = "setup.exe /configure Install.xml ," & strFolder
objShell.Run strPath
您的代碼很可能不在腳本文件夾中找到並運行setup.exe
,而是在%PATH%
中的某個位置找到了另一個setup.exe
。
只是將文件夾附加到命令行並不能完成您想要的操作。 有兩種方法可以解決此問題:
按照@AlexK的建議,使用完整路徑運行setup.exe
。 。 您可能還需要提供Install.xml
的完整路徑。 使用BuildPath
方法構造路徑。 您可能還希望在路徑周圍添加引號,以照顧路徑中的空格。
Function qq(str) : qq = """" & str & """" : End Function strPath = qq(objFSO.BuildPath(strFolder, "setup.exe")) & " /configure " & _ qq(objFSO.BuildPath(strFolder, "Install.xml")) objShell.Run strPath
將工作目錄更改為包含腳本和setup.exe
的文件夾,然后運行不帶路徑(或相對路徑.\\setup.exe
)的命令。
objShell.CurrentDirectory = strFolder strPath = "setup.exe /configure Install.xml" objShell.Run strPath
多謝你們! 我將其混合並使其適用於我。 (不確定是否可以使某些東西更清潔,但是它可以工作!)
Dim WshShell
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set objShell = CreateObject("Wscript.Shell")
Set WshEnv = WshShell.Environment("PROCESS")
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
objShell.CurrentDirectory = strFolder
WshEnv("SEE_MASK_NOZONECHECKS") = 1
WshShell.Run("setup.exe /Configure Install.xml"), 0, true
WshEnv.Remove("SEE_MASK_NOZONECHECKS")
wscript.quit(RetVal)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.