2013-04-16 3 views
1

Я новичок в файлах VBScript ЕСЛИ я пытаюсь проверить версию ОС, если это Microsoft Windows XP Professional или Microsoft Windows 7 Professional Мне нужна помощь, как я могу исправить этот следующий код:IF в 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 
Смежные вопросы