Microsoft VBscript运行时错误:需要对象:';[string:“new 1.cmd”和“x27”。不确定到底是什么导致了这种情况的发生

Microsoft VBscript运行时错误:需要对象:';[string:“new 1.cmd”和“x27”。不确定到底是什么导致了这种情况的发生,vbscript,Vbscript,这是我的密码: Dim strContents, objRegx, mkey, objShell, objUser, objFile Set objShell = CreateObject("WScript.Shell") Set objRegx = New RegExp Set objFSO = CreateObject("Scripting.FileSystemObject") Set objString = CreateObject("Scripting.Dictionary") Set

这是我的密码:

Dim strContents, objRegx, mkey, objShell, objUser, objFile
Set objShell = CreateObject("WScript.Shell")
Set objRegx = New RegExp
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objString = CreateObject("Scripting.Dictionary")
Set objUser = CreateObject("Wscript.Network")
Set objPath = objFSO.BuildPath(CurrentDirectory, """new 1.cmd""")

objRegx.Pattern = "\[(.*?)\]"
objRegx.IgnoreCase = True
objRegx.Global = True

WScript.Echo "Acquiring data ..."
objShell.Run objPath, 1, True

Set objFile = objFSO.OpenTextFile("c:\windows\temp\plik1.txt")

strContents = objFile.ReadAll

mkey = objRegx.Replace(strContents, "")

WScript.Echo mkey

objFile.Close
我不确定运行脚本时为什么会出现此错误

您在该声明中有3个错误:

  • “new 1.cmd”
    中嵌套的双引号使它们成为实际文件名的一部分,即
    FileSystemObject
    方法可以自己处理带有空格的路径,而不需要额外的双引号。但是,在向方法传递路径时,确实需要添加双引号
  • WshShell
    对象的属性,不是内置变量
  • 该方法返回字符串,而不是对象,因此需要删除关键字
这将满足您的要求:

objPath = objFSO.BuildPath(objShell.CurrentDirectory, "new 1.cmd")
...
objShell.Run """" & objPath & """", 1, True

我想说错误是
Set objPath=objFSo.BuildPath(CurrentDirectory,““new 1.cmd”“”)
。所需对象:'[string:'C:\Users\wojte\u 000\D']哦,对不起。非常感谢你给出的清晰而有教育意义的答案
objPath = objFSO.BuildPath(objShell.CurrentDirectory, "new 1.cmd")
...
objShell.Run """" & objPath & """", 1, True