VBS脚本错误

时间:2013-05-23 17:33:31

标签: vbscript compilation

我为vbs的“新鲜感”提前道歉。我正在尝试运行此脚本来搜索我的文件服务器上的所有pst文件。此时,我收到此错误:

searchpst.vbs(6,26)Microsfot VBScript编译错误:语句的预期结束。

我试图运行的脚本当然名为searchpst.vbs,我知道(6,26)是错误的行和字符数,但我似乎无法弄清楚如何解决它?以下是我的脚本,非常感谢帮助!

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
strsql = "Select" * from CIM_DataFile Where Extension = '"pst"'"
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\test.csv",2,true)

For Each objFile in colFiles

    Wfile.writeline(strComputer & " " & objFile.Drive & " " & objFile.Path & " " & objFile.FileName & "." & objFile.Extension & " " & objFile.FileSize)

2 个答案:

答案 0 :(得分:1)

我重新格式化了代码以便于阅读。单个撇号'将其后面的所有内容更改为注释,因此它不是代码的一部分。因此'"pst"'"不可见。

实际上,存在的问题不止于此。整行的格式不正确,我认为你还有其他几行无序。它应该看起来像这样,我想:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strsql = "Select * from CIM_DataFile Where Extension = 'pst'"
Set colFiles = objWMIService.ExecQuery(strsql)
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\test.csv",2,true)

For Each objFile in colFiles
    Wfile.writeline(strComputer & " " & objFile.Drive & " " & objFile.Path & " " & objFile.FileName & "." & objFile.Extension & " " & objFile.FileSize)
Next

答案 1 :(得分:0)

如果调用函数来接收其返回值,则需要param list();和_继续一行 - 所以改变:

Set colFiles = objWMIService.ExecQuery _
strsql = "Select" * from CIM_DataFile Where Extension = '"pst"'"

strsql = "Select * from CIM_DataFile Where Extension = 'pst'"
Set colFiles = objWMIService.ExecQuery(strsql)

或:

Set colFiles = objWMIService.ExecQuery( _
     "Select * from CIM_DataFile Where Extension = 'pst'")

在阅读@ Joe的(+1)回答后,我尝试清理SQL中的引用。