none
script de comparação RRS feed

  • Pergunta

  • pessoal bom dia, eu preciso identificar qual o tipo do meu sistema operacional e fiz o seguinte script bobo com ajuda do script guy

     

    onde no final eu comparo a saida do "campo caption" = meu sistema operacional com outros tipos de sistema, ele compila e nao mostra a semelhanca real do sistema (estou rodando em cima de windows xp)

     

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
    Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For Each objOS in colOSes
      Wscript.Echo "Caption: " & objOS.Caption 'Name
      WScript.Echo "Service Pack: " & objOS.ServicePackMajorVersion & "." & _
       objOS.ServicePackMinorVersion
    Next

    str1 = "Microsoft Windows XP Professional"
    mysystem = "& objOS.Caption 'Name"
    str3 = "Microsoft Windows 2000 Professional"
    str4 = "Microsoft Windows 2000 Server"
    str5 = "Microsoft Windows 2003 Server"

    Wscript.Echo "& _ str1"

    If str1 = mysystem Then
        Wscript.Echo "The strings are equal."
    Else
        Wscript.Echo "The strings are not equal."
    End If

    If str3 = mysystem Then
        Wscript.Echo "The strings are equal."
    Else
        Wscript.Echo "The strings are not equal."
    End If

    If str4 = mysystem Then
        Wscript.Echo "The strings are equal."
    Else
        Wscript.Echo "The strings are not equal."
    End If

    If str5 = mysystem Then
        Wscript.Echo "The strings are equal."
    Else
        Wscript.Echo "The strings are not equal."
    End If

     

     

    ### compilando

     

    C:\>cscript compara.vbs
    Microsoft (R) Windows Script Host Versão 5.7
    Copyright (C) 1996-2001 Microsoft Corporation. Todos os direitos reservados.

    Caption: Microsoft Windows XP Professional
    Service Pack: 3.0
    & _ str1
    The strings are not equal.
    The strings are not equal.
    The strings are not equal.
    The strings are not equal.

     

     

    terça-feira, 2 de setembro de 2008 14:49

Respostas

  • Olá amigo, blza ?

     

    Primeiro marque o post como util caso tenha ajudado.

     

    Segue abaixo este link:

     

    http://www.computerperformance.co.uk/ezine/ezine52.htm

     

     OSVer.vbs
    ' Purpose VBScript to discover the operating system version.
    ' Learning Points: Win32_ WMI objects. Case Select
    ' Usage if want to 'branch' depending on the OS
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.2 - April 2007
    ' --------------------------------------------------------------'
    Option Explicit
    Dim objWMI, objItem, colItems
    Dim strComputer, VerOS, VerBig, Ver9x, Version9x, OS, OSystem

    ' Here is where we interrogate the Operating System
    ' On Error Resume Next

    ' Get the computer name dot = this computer.
    strComputer = "."
    ' This is where WMI interrogates the operating system
    Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)

    ' Here we filter Version from the dozens of properties
    For Each objItem in colItems
    VerBig = Left(objItem.Version,3)
    Next

    ' Spot VerBig variable in previous section
    ' Note the output variable is called OSystem

    Select Case VerBig
    Case "6.0" OSystem = "Vista"
    Case "5.2" OSystem = "Windows 2003"
    Case "5.1" OSystem = "XP"
    Case "5.0" OSystem = "W2K"
    Case "4.0" OSystem = "NT 4.0**"
    Case Else OSystem = "Unknown - probably Win 9x"
    End Select

    Wscript.Echo "Version No : " & VerBig & vbCr _
    & "OS System : " & OSystem

    WScript.Quit

    ' End of script

     

     

    Realizei os testes e funcionou.

     

    Att.

     

    Leonardo Duarte

     

    • Marcado como Resposta Thiago Beier quinta-feira, 17 de dezembro de 2009 21:48
    terça-feira, 2 de setembro de 2008 16:30