Newsgroup: it.comp.lang.visual-basic
Titolo: Sistema Operativo: client o server ?

Ciao a tutti,
    ho scritto un piccolo applicativo che rileva informazioni sw/hw del pc;
per rilevare il sistema operativo utilizzo l'API GetVersionEx.
Purtroppo riesco solo a determinare se si tratta di Win95/98/NT4 o 2000.
Qualcuno sa come posso distinguere NT4 Workstation da NT4 Server ? E
ovviamente le varie differenze nella famiglia Win2000 ?
Ciao
Gianluca


Hai messo il dito nella piaga :(
Aggiungici pure winMe w Whistler, pardon XP e tutto obsolesce alla velocita' 
della luce.
Ho portato in vb un esempio della platform sdk, con qualche piccola correzione
(non so perche' ma gli esempi non vanno mai alla prima !)
L' ho provato con win nt 4 sp6, win 2K no sp, win 98.
Attendo il parere di altri tester.
Il codice e' sotto la firma.
ciao, hal
====================================================
Option Explicit
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_NT_WORKSTATION = &H1
Private Const VER_NT_DOMAIN_CONTROLLER = &H2
Private Const VER_NT_SERVER = &H3
Private Const VER_SERVER_NT = &H80000000
Private Const VER_WORKSTATION_NT = &H40000000
Private Const VER_SUITE_SMALLBUSINESS = &H1
Private Const VER_SUITE_ENTERPRISE = &H2
Private Const VER_SUITE_BACKOFFICE = &H4
Private Const VER_SUITE_COMMUNICATIONS = &H8
Private Const VER_SUITE_TERMINAL = &H10
Private Const VER_SUITE_SMALLBUSINESS_RESTRICTED = &H20
Private Const VER_SUITE_EMBEDDEDNT = &H40
Private Const VER_SUITE_DATACENTER = &H80
Private Const VER_SUITE_SINGLEUSERTS = &H100
Private Const VER_SUITE_PERSONAL = &H200
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const KEY_QUERY_VALUE = &H1
Private Type OSVERSIONINFOEX
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    wServicePackMajor As Integer
    wServicePackMinor As Integer
    wSuiteMask As Integer
    wProductType As Byte
    wReserved As Byte
End Type
Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128      '  Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" ( _
                        lpVersionInformation As OSVERSIONINFOEX) As Long
 
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" ( _
                        ByVal hKey As Long, ByVal lpSubKey As String, _
                        ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long _
                        ) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
                        ByVal hKey As Long, ByVal lpValueName As String, _
                        ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long _
                        ) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegCloseKey Lib "advapi32.dll" ( _
                        ByVal hKey As Long) As Long
Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" ( _
                        ByVal lpString1 As String, ByVal lpString2 As String) As Long
'// =======================================================================
Public Function DisplaySystemVersion(ByRef retOS As String, _
                                    ByRef retSuite As String, _
                                    ByRef retVersion As String, _
                                    ByRef retBuild As String _
                                    ) As Boolean
    Dim osviEx As OSVERSIONINFOEX
    Dim osvi As OSVERSIONINFO
    Dim bOsVersionInfoEx As Boolean
    Dim strVersion As String
    retOS = vbNullString
    retSuite = vbNullString
    retVersion = vbNullString
    retBuild = vbNullString
 
    '// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
    '//
    '// If that fails, try using the OSVERSIONINFO structure.
    osviEx.dwOSVersionInfoSize = Len(osviEx)
    If (bOsVersionInfoEx = GetVersionEx(osviEx)) Then
        '// If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
        osviEx.dwOSVersionInfoSize = Len(osvi)
        If (False = GetVersionEx(osviEx)) Then
            '// nothing to do !
           Exit Function
        End If
    Else
        bOsVersionInfoEx = True
    End If
    Select Case (osviEx.dwPlatformId)
    Case VER_PLATFORM_WIN32_NT:
        '// Test for the product.
        If (osviEx.dwMajorVersion <= 4) Then
            retOS = "Microsoft Windows NT "
        ElseIf (osviEx.dwMajorVersion = 5 And osviEx.dwMinorVersion = 0) Then
            retOS = "Microsoft Windows 2000 "
        ElseIf (osviEx.dwMajorVersion = 5 And osviEx.dwMinorVersion = 1) Then
            retOS = "Whistler "
        End If
        '// Test for product type.
        If (bOsVersionInfoEx) Then
            If (osviEx.wProductType = VER_NT_WORKSTATION) Then
               If (osviEx.wSuiteMask And VER_SUITE_PERSONAL) Then
                  retSuite = "Personal "
               Else
                  retSuite = "Professional "
               End If
            ElseIf (osviEx.wProductType = VER_NT_SERVER) Then
               If (osviEx.wSuiteMask And VER_SUITE_DATACENTER) Then
                  retSuite = "DataCenter Server "
               ElseIf (osviEx.wSuiteMask And VER_SUITE_ENTERPRISE) Then
                  retSuite = "Advanced Server "
               Else
                  retSuite = "Server "
               End If
            ElseIf (osviEx.wProductType = VER_NT_DOMAIN_CONTROLLER) Then
              retSuite = "Domain Controller "
            End If
         Else
            Dim hKey As Long
            Dim szProductType As String * 80
            Dim dwBufLen As Long
            RegOpenKeyEx HKEY_LOCAL_MACHINE, _
                        "SYSTEM\CurrentControlSet\Control\ProductOptions", _
                        0, KEY_QUERY_VALUE, hKey
            RegQueryValueEx hKey, "ProductType", 0&, 0&, szProductType, dwBufLen
            RegCloseKey hKey
            If (lstrcmpi("WINNT", szProductType) = 0) Then
                retSuite = "Workstation "
            ElseIf (lstrcmpi("SERVERNT", szProductType) = 0) Then
                retSuite = "Server "
            End If
 
         End If     '// bOsVersionInfoEx
      '// Display version, service pack (if any), and build number.
         If (osviEx.dwMajorVersion <= 4) Then
            retVersion = CStr(osviEx.dwMajorVersion) & "." & _
                            CStr(osviEx.dwMinorVersion) & " " & _
                            Sz2Str(osviEx.szCSDVersion)
            retBuild = CStr(osviEx.dwBuildNumber And &HFFFF)
         Else
            retVersion = Sz2Str(osviEx.szCSDVersion)
            retBuild = CStr(osviEx.dwBuildNumber And &HFFFF)
        End If
    Case VER_PLATFORM_WIN32_WINDOWS:
        If (osviEx.dwMajorVersion = 4 And osviEx.dwMinorVersion = 0) Then
             retOS = "Microsoft Windows 95 "
             If (Left$(osviEx.szCSDVersion, 1) = "C") Then
                retOS = retOS & " OSR2 "
             End If
 
        ElseIf (osviEx.dwMajorVersion = 4 And osviEx.dwMinorVersion = 10) Then
                retOS = "Microsoft Windows 98 "
             If (Left$(osviEx.szCSDVersion, 1) = "A") Then
                retOS = retOS & " SE "
             End If
 
        ElseIf (osviEx.dwMajorVersion = 4 And osviEx.dwMinorVersion = 90) Then
                retOS = "Microsoft Windows Me "
        End If
    Case VER_PLATFORM_WIN32s:
         retOS = "Microsoft Win32s "
 
    End Select
    DisplaySystemVersion = True
End Function    '// DisplaySystemVersion
Public Sub TestDisplaySystemVersion()
    Dim OS As String, Suite As String, Version As String, Build As String
    If (DisplaySystemVersion(OS, Suite, Version, Build)) Then
        Debug.Print "OS: " & OS
        Debug.Print "Suite: " & Suite
        Debug.Print "Version: " & Version
        Debug.Print "Build: " & Build
        MsgBox OS & vbLf & Suite & vbLf & Version & vbLf & Build
    Else
        Debug.Print "DisplaySystemVersion failed !"
        MsgBox "DisplaySystemVersion failed !"
    End If
End Sub
Public Function Sz2Str(ByRef szStr As String) As String
    Dim ich As Integer
    ich = InStr(1, szStr, Chr$(0), vbBinaryCompare)
    If (ich) Then
        Sz2Str = Trim$(Left$(szStr, ich - 1))
    Else
        Sz2Str = Trim$(szStr)
    End If
End Function

 wrote in message
news:9fvud5$63d0m$1...@ID-56381.news.dfncis.de...


 wrote:
Aggiungo il codice per 
VB.NET
 (non e' testato perche' scritto
direttamente in OE):
Dim osv As OperatingSystem
osv = Environment.OSVersion
Select Case osv.Platform
    Case PlatformID.Win32NT
        Debug.WriteLineIf((osv.Version.Major = 5 And
osv.Version.Minor =
0), "Windows 2000 " & osv.CSD)
        Debug.WriteLineIf((osv.Version.Major = 5 And
osv.Version.Minor =
1), "Whistler")
    Debug.WriteLineIf((osv.Version.Major < 5), "Windows NT" &
osv.Version.Major.ToString & osv.CSD)
    Case PlatformID.Win32S
        Debug.WriteLine("Win32s")
    Case PlatformID.Win32Windows
        Debug.WriteLineIf((osv.Version.Major = 4 And
osv.Version.Minor = 0), "Windows 95 " & osv.CSD)
        Debug.WriteLineIf((osv.Version.Major = 4 And
osv.Version.Minor = 10), "Windows 98 " & osv.CSD)
        Debug.WriteLineIf((osv.Version.Major = 4 And
osv.Version.Minor = 90), "Windows ME " & osv.CSD)
End Select
Ciao.

direttamente in OE):
[zac!]
Splendido :)
Ci pensiamo noi a testarlo, thanks mille !
ciao, hal

Mi scuso per l'errata quotatura dell'ultimo reply prontamente segnalatomi,
sicuramente non riaccadra'...
Risultati dei test:
Windows 2000 Professional ---> OK
Windows 2000 Server ---------> OK
Su NT 4 Workstation con sp5 mi fornisce il seguente output:
    Microsoft Windows NT Professional 4.0 Service Pack 5.0 1381
Su NT4 Server da' un errore analogo.
Ciao
Gianluca

Su NT4 Server da' un errore analogo.
Grazie 1000 per i test :)
L' nt server e' stand-alone o domain controller (primary/backup ?)
(in effetti l' avevo provato con un nt 4 srv bdc)
ciao, hal


Preferirei che mi mandi il prg via email perchè in quel modo non ci
capisco niente! Ma poi, che fa il tuo prg?
s.a...@inwind.it
Ciao,
     Salvo

capisco niente! Ma poi, che fa il tuo prg?
penso che tu abbia mischiato il post di Gianluca con il mio :(
Gianluca ha scritto un programma (che fa qualcosa, ovviamente, ma qui
non ci interessa) ed ha la necessita' di identificare con precisione il sistema 
operativo (con le relative varianti) sul quale il programma gira.
A tale scopo ho trasportato in vb (con alcune modifiche) un esempio
tratto dalla platform sdk.
ciao, hal
p.s. ammesso che io abbia inteso correttamente il tuo intervento :)

 wrote in message
news:9g5m0c$78ort$1...@ID-56381.news.dfncis.de...
