Vbscript 在vbs/hta中带有or子句的If then语句

Vbscript 在vbs/hta中带有or子句的If then语句,vbscript,wmi,hta,Vbscript,Wmi,Hta,我有一段VBScript代码,根据特定的名称条件查询Win32\u服务。现在我们已经将半个环境迁移到了新名称,所以我需要修改脚本以在任何一种情况下运行代码块。我在网上搜索过,但找不到任何例子。我正在粘贴两个代码块。我需要查询RGL或Reed作为服务名称的开始,并返回结果。欢迎提出任何意见 ' Initialize Objects. Set g_objWMIService = GetObject("winmgmts:\\.") Set g_colServices = g_objWMISe

我有一段VBScript代码,根据特定的名称条件查询
Win32\u服务
。现在我们已经将半个环境迁移到了新名称,所以我需要修改脚本以在任何一种情况下运行代码块。我在网上搜索过,但找不到任何例子。我正在粘贴两个代码块。我需要查询RGL或Reed作为服务名称的开始,并返回结果。欢迎提出任何意见

 ' Initialize Objects.
  Set g_objWMIService = GetObject("winmgmts:\\.")
  Set g_colServices = g_objWMIService.InstancesOf("Win32_Service")

  If c_Debug Then h_divStatus.style.display = "block"

   For Each g_objService In g_colServices 
    'Status "Checking service..."
    If c_Reedonly Then
      If LCase(Left(g_objService.DisplayName, 4)) = LCase("RGL ") Then
'      'If c_Debug Then
'        'WScript.Echo "Name: " & g_objService.Name & vbCrLf & _ 
'        '    "Display Name: " & g_objService.DisplayName & vbCrLf & _ 
'        '    " Description: " & g_objService.Description & vbCrLf & _ 
'        '    " Path Name: " & g_objService.PathName & vbCrLf & _ 
'        '    " Start Mode: " & g_objService.StartMode & vbCrLf & _ 
'        '    " State: " & g_objService.State & vbCrLf 
'        'AddRowLinePartial(g_objService.Name)
        AddRowLinePartial "h_tblServices", g_objService.DisplayName, g_objService.Name, g_objService.State, g_objService.StartMode
      End If
    Else
      AddRowLinePartial "h_tblServices", g_objService.DisplayName, g_objService.Name, g_objService.State, g_objService.StartMode
    End if
    Next
    Else
    For Each g_objService In g_colServices 
    'Status "Checking service..."
    If c_Reedonly Then
      If LCase(Left(g_objService.DisplayName, 4)) = LCase("Reed") Then
'      'If c_Debug Then
'        'WScript.Echo "Name: " & g_objService.Name & vbCrLf & _ 
'        '    "Display Name: " & g_objService.DisplayName & vbCrLf & _ 
'        '    " Description: " & g_objService.Description & vbCrLf & _ 
'        '    " Path Name: " & g_objService.PathName & vbCrLf & _ 
'        '    " Start Mode: " & g_objService.StartMode & vbCrLf & _ 
'        '    " State: " & g_objService.State & vbCrLf 
'        'AddRowLinePartial(g_objService.Name)
        AddRowLinePartial "h_tblServices", g_objService.DisplayName, g_objService.Name, g_objService.State, g_objService.StartMode
      End If
    Else
      AddRowLinePartial "h_tblServices", g_objService.DisplayName, g_objService.Name, g_objService.State, g_objService.StartMode
    End if
  Next 

只需在If语句中使用Or关键字。你可以同时做这两件事

' Initialize Objects.
Set g_objWMIService = GetObject("winmgmts:\\.")
Set g_colServices = g_objWMIService.InstancesOf("Win32_Service")

If c_Debug Then h_divStatus.style.display = "block"

For Each g_objService In g_colServices 
    'Status "Checking service..."
    If c_Reedonly Then
        If LCase(Left(g_objService.DisplayName, 4)) = LCase("RGL ") _
                Or LCase(Left(g_objService.DisplayName, 4)) = LCase("Reed") Then
'   'If c_Debug Then
'   'WScript.Echo "Name: " & g_objService.Name & vbCrLf & _ 
'   '   "Display Name: " & g_objService.DisplayName & vbCrLf & _ 
'   '   " Description: " & g_objService.Description & vbCrLf & _ 
'   '   " Path Name: " & g_objService.PathName & vbCrLf & _ 
'   '   " Start Mode: " & g_objService.StartMode & vbCrLf & _ 
'   '   " State: " & g_objService.State & vbCrLf 
'   'AddRowLinePartial(g_objService.Name)
            AddRowLinePartial "h_tblServices", g_objService.DisplayName, g_objService.Name, g_objService.State, g_objService.StartMode
        End If
    Else
        AddRowLinePartial "h_tblServices", g_objService.DisplayName, g_objService.Name, g_objService.State, g_objService.StartMode
    End If
Next