如果满足语句则启动程序

start a program if a statement is met

我想在我的电脑上建立一个权限级别系统,所以我想要一个 vbs 程序来检查文件是否存在,如果存在则启动程序但它说错误行 5 字符 1 对象需要“但是当我这样做时它说预期的声明

Option Explicit
DIM fso  
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
If fso.FileExists("C:\code\login\authlevel.txt") or 
fso.FileExists("C:\code\login\authlevel.txt") or 
fso.FileExists("C:\code\login\authlevel.txt") Then
objShell.Run("""C:\Program Files 
(x86)\Google\Chrome\Application\chrome.exe""")
Set objShell = Nothing
 WScript.Quit()
Else
  WScript.Echo("incorrect autority")
End If

WScript.Quit()

任何帮助都会很好

首先,您没有将 fso 设置为任何东西,但您试图将其用作文件系统对象,您需要 set 该引用,正如我在下面所做的那样。

您似乎还在 OR 语句中将代码拆分为多行。如果你想这样做(通常是出于可读性目的)你需要告诉 vbscript 下一行是代码的延续而不是像这样的新代码行,使用下划线字符:

Option Explicit
DIM fso  
set fso = CreateObject("Scripting.FileSystemObject")
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
If fso.FileExists("C:\code\login\authlevel.txt") or _ 
fso.FileExists("C:\code\login\authlevel.txt") or _ 
fso.FileExists("C:\code\login\authlevel.txt") Then
objShell.Run("""C:\Program Files 
(x86)\Google\Chrome\Application\chrome.exe""")
Set objShell = Nothing
 WScript.Quit()
Else
  WScript.Echo("incorrect authority")
End If

WScript.Quit()