【问题标题】:VBS - file not foundVBS - 找不到文件
【发布时间】:2014-05-29 03:39:47
【问题描述】:

我正在尝试检查我的 PC 是否在目录中确实有例如 Outlook.exe(它确实有),但是在运行代码 FileExists 时会自动返回 false,这会导致我显示该文件不存在的消息。你能帮帮我吗?

Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject( "WScript.Shell" )

outlook15 = "%ProgramFiles(x86)%\Microsoft Office\Office15\outlook.exe"

If (fso.FileExists("%ProgramFiles(x86)%\Microsoft Office\Office15\OUTLOOK.exe")) Then  
    msgbox outlook15 & " exists."
Else
    msgbox outlook15 & "doesn't exists."    
End If

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    您需要使用ExpandEnvironmentStrings%ProgramFiles(x86)% 转换为正确的路径。

    strPath = WshShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
    outlook15 = strPath & "\Microsoft Office\Office15\outlook.exe"
    
    If fso.FileExists(outlook15) Then
        msgbox outlook15 & " exists."
    Else
        msgbox outlook15 & " doesn't exist."
    End If
    

    【讨论】:

    • 好的,谢谢它的工作,但现在如果它是真的尝试使用WshShell.Run(outlook15) 打开 Outlook,它说“系统找不到指定的文件”
    • 那是因为Run() 函数需要在任何包含空格的路径周围加上引号。请改用WshShell.Run Chr(34) & outlook15 & Chr(34)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多