我正在尝试chceck如果我的PC确实有例如目录中的outlook.exe(它确实)但是当运行代码FileExists时,aperently返回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
答案 0 :(得分:3)
您需要使用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