在VBScript中运行带有参数的exe文件 [英] Running an exe file with parameters in a VBScript

查看:781
本文介绍了在VBScript中运行带有参数的exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个从脚本所在的文件夹中运行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. /p>

仅将文件夹添加到命令行不会执行您想要的操作.有两种方法可以解决此问题:

  • 使用完整路径运行setup.exe,如 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
    

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

解决方案

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
    

这篇关于在VBScript中运行带有参数的exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆