1

我是 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
}

非常感谢您的帮助

4

5 回答 5

2

如果您删除代码片段最后一行中的“}”会发生什么?

于 2013-04-16T22:57:22.253 回答
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
于 2013-06-10T18:44:22.120 回答
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"
于 2013-10-21T13:44:10.663 回答
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
于 2014-08-07T01:30:46.493 回答
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
于 2013-04-29T10:12:39.557 回答