Running an exe file with parameters in a VBScript

后端 未结 2 692
说谎
说谎 2021-01-24 17:15

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

相关标签:
2条回答
  • 2021-01-24 17:46

    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)
    
    0 讨论(0)
  • 2021-01-24 17:54

    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.exe with the full path, as suggested by @AlexK.. You probably need to provide the full path to Install.xml too. 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 strPath
      
    • Change the working directory to the folder containing your script and setup.exe and run the command without path (or the relative path .\setup.exe).

      objShell.CurrentDirectory = strFolder
      strPath = "setup.exe /configure Install.xml"
      objShell.Run strPath
      
    0 讨论(0)
提交回复
热议问题