2013-04-16 59 views
1

我是VBScript文件的初學者如果我嘗試驗證操作系統的版本,如果是Microsoft Windows XP Professional或Microsoft Windows 7 Professional我需要幫助我該如何解決以下代碼:如果在VBS中沒有驗證

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 
} 

非常感謝你的幫助

+1

什麼是代碼中的問題?請提供錯誤/警告? – Hiten004

+0

以上代碼正在爲我工​​作 – Hiten004

回答

2

會發生什麼事,如果你刪除「}」在您的代碼段的最後一行?

+0

Hoo這部分是隻有當我把代碼放在這個頁面上對不起有機代碼沒有這個字符「{}」 – j054d3c

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 
+0

不工作我運行我有同樣的問題是讓我的消息「不支持」 – j054d3c

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 
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" 
0

你可以試試這個


    '---------------------------------------------------- 
    ' CODE BY: zhangbo2012 
    ' Email : [email protected] 
    ' 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