组合目录和一个批处理文件中的一行,以执行 [英] Combining a directory and a batch file to execute in one line
问题描述
我如何可以结合一个目录(比如C:\\ Program Files文件\\ DIR1),这是一个变量,来自于的InstallShield属性和批处理脚本中下的test.bat一行来执行(C:\\ Program Files文件\\ DIR1 \\ test.bat的)?我尝试了以下,但徒劳无功。
How can I combine a directory(say C:\Program Files\dir1) which is in a variable and comes from a property in installshield and a batch script test.bat to execute in a single line (C:\Program Files\dir1\test.bat)??? I was trying the below but in vain.
dim shell
dim strInstallLocation, strbatch
set shell=createobject("wscript.shell")
strInstallLocation = """C:\Program Files\dir1"""
strbatch = strInstallLocation &"""\test.bat"""
shell.run strbatch
set shell=nothing
我得到一个类型不匹配的属性。我是新来这个vbscripting。如果它是一个基本的请甚至帮助。
I get a type mismatch property. I am new to this vbscripting. Please help even if it is a basic.
推荐答案
(第一个)参数.RUN应该被引用,以帮助外壳正确解析文件规范。对于您可以使用:
The (first) parameter to .Run should be quoted to help the shell to parse the file specification correctly. For that you can use:
Function qq(s) : qq = """" & s & """" : End Function
要建立一个文件夹/路径和文件名的文件的规范,一个FileSystemObject提供.BuildPath方法。它应该被用来代替本土的字符串操作(假设你已经在goFS的FSO):
To build a file specification from a folder/path and a file name, the FileSystemObject provides the .BuildPath method. It should be used instead of home grown string operations (assuming you have an FSO in goFS):
>> sFolder = "C:\Program Files\dir1"
>> sFile = "magic.bat"
>> sFSpec = goFS.BuildPath(sFolder, sFile)
组合的设计:
>> sCmd = qq(sFSpec)
>> WScript.Echo sCmd
>>
"C:\Program Files\dir1\magic.bat"
这篇关于组合目录和一个批处理文件中的一行,以执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!