如果在VBS中没有验证

时间:2013-04-16 21:49:53

标签: vbscript

我是VBScript文件的初学者如果我尝试验证操作系统的版本,如果是Microsoft Windows XP Professional或Microsoft Windows 7 Professional我需要帮助如何修复以下代码:

set service = GetObject ("winmgmts:")
Dim os_7, os_xp
os_7="Microsoft Windows 7 Professional"
os_xp="Microsoft Windows XP Professional"
for each Process in Service.InstancesOf ("Win32_Process")
    If Process.Name = "notes2.exe"  then
        WScript.Echo "Please Close the Lotus Notes Application and try again"
        WScript.quit
    End If
exit for

next
Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") 

for each System in SystemSet 

 WScript.Echo System.Caption 
    If System.Caption = os_7 Then

        WScript.Echo "in  7"
    Else If System.Caption = os_xp Then

            WScript.Echo "in XP"
            WScript.quit
        Else 
            WScript.Echo "Is not supported "
        End If
    End If
Exit for
next
}

非常感谢你的帮助

5 个答案:

答案 0 :(得分:2)

如果删除"}"会发生什么?在代码段的最后一行?

答案 1 :(得分:0)

此代码经典用于古老的SELECT CASE

set service = GetObject ("winmgmts:")
Dim os_7, os_xp
os_7="Microsoft Windows 7 Professional"
os_xp="Microsoft Windows XP Professional"
for each Process in Service.InstancesOf ("Win32_Process")
    If Process.Name = "notes2.exe"  then
        WScript.Echo "Please Close the Lotus Notes Application and try again"
        WScript.quit
    End If
exit for

next
Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") 

for each System in SystemSet 

 WScript.Echo System.Caption
Select Case System.Caption
Case os_7

        WScript.Echo "in  7"
Case os_xp

            WScript.Echo "in XP"
            WScript.quit
Case Else 
            WScript.Echo "Is not supported "
End Select
Exit for
next

答案 2 :(得分:0)

我用以下内容替换了你的选择案例部分,并让它发挥作用。

set service = GetObject ("winmgmts:")

for each Process in Service.InstancesOf ("Win32_Process")
    If Process.Name = "notes2.exe"  then
        WScript.Echo "Please Close the Lotus Notes Application and try again"
        WScript.quit
    End If
exit for

next
Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") 

for each System in SystemSet 
    WScript.Echo System.caption
    If (instr(System.Caption, "Windows 7")) Then
        wscript.echo "Windows 7 found"
    ElseIF (instr(System.Caption, "Windows XP")) Then
        Wscript.echo "Windows xp found."
    Else
        Wscript.echo "Unsuported Operating system."
    End If
Exit for
next

答案 3 :(得分:0)

strVer = wshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")   
arrVer = Split(strVer, ".")

if arrVer(0) = 5 then "XP"
      if arrVer(0) = 6 AND arrVer(1) = 0  then "Vista"
      if arrVer(0) = 6 AND arrVer(1) = 1 then "Win7"
      if arrVer(0) = 6 AND arrVer(1) = 2 then "Win8"
      if arrVer(0) = 6 AND arrVer(1) = 3 then "Win Blue"

答案 4 :(得分:0)

你可以试试这个


  '----------------------------------------------------
  ' CODE BY: zhangbo2012
  ' Email  : zhangbo2012@outlook.com
  ' FROM   : China
  '----------------------------------------------------
  ' WMI:Win32_OperatingSystem
  '----------------------------------------------------
   On error resume next
   Set WMI_Obj = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_OperatingSystem", , 48)
   For each obj in WMI_Obj
        wscript.echo " Caption = " & obj.Caption
   Next