quarta-feira, 16 de abril de 2014

This is gonna blow your mind - Operation System Identification

You know there's a lot of  routines to identify Operation System, but none of them are as classy or as elegant as the following one.

This code is not mine. My friend Cicero came to me with this code and found it fantastic!

I know it's VB6, it's old stuff. But with all this fuss about Operational System migration (people leaving Windows XP and adoptint Windows 7 and or Windows 8) I believe a code like that will be extremely useful.
Look at the elegance. Amazing!

Public Function MyOSVersion() As String
    Dim lstrResult As String
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", , 48)
    For Each objItem In colItems
        lstrResult = "OS Name: " & objItem.Caption & vbNewLine & "Version: " & objItem.Version
        Exit For
    Next
    MyOSVersion = lstrResult
End Function

Public Function isWindows8() As Boolean
      Dim lstrResult As String
      lstrResult = MyOSVersion
      isWindows8 = (InStr(1, lstrResult, "Microsoft Windows 8") > 0)
End Function


Public Function isWindowsXP() As Boolean
      Dim lstrResult As String
      lstrResult = MyOSVersion
      isWindowsXP = (InStr(1, lstrResult, "Microsoft Windows XP") > 0)
End Function

Nenhum comentário:

Postar um comentário