问题
I need to create a script that runs setup.exe /configure Install.xml from the folder the script is located.
When I run the script below, it does find the setup.exe but it does not read the parameters. It is like the last part (/configure Install.xml) is not being read.
Script:
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
回答1:
Most likely your code doesn't find and run the setup.exe in the script folder, but a different setup.exe somewhere in the %PATH%.
Simply appending the folder to the commandline is not going to do what you want. There are two ways for you to solve this issue:
Run
setup.exewith the full path, as suggested by @AlexK.. You probably need to provide the full path toInstall.xmltoo. Use the BuildPath method for constructing the paths. You may also want to add quotes around the paths to take care of spaces in them.Function qq(str) : qq = """" & str & """" : End Function strPath = qq(objFSO.BuildPath(strFolder, "setup.exe")) & " /configure " & _ qq(objFSO.BuildPath(strFolder, "Install.xml")) objShell.Run strPathChange the working directory to the folder containing your script and
setup.exeand run the command without path (or the relative path.\setup.exe).objShell.CurrentDirectory = strFolder strPath = "setup.exe /configure Install.xml" objShell.Run strPath
回答2:
Thanks guys! I mixed it up and made this that works for me. (Not sure if something could be made cleaner, but it works!)
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)
来源:https://stackoverflow.com/questions/40041460/running-an-exe-file-with-parameters-in-a-vbscript