Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 21
  1. #1
    Utente di HTML.it L'avatar di rs125
    Registrato dal
    May 2008
    Messaggi
    193

    [VB6]Rilevare versione di Windows

    Ciao a tutti,avevo scritto precedentemente in un altro post ma giustamente i moderatori mi hanno invitato,come pensavo, a creare una nuova discussione per evitare pasticci!

    Avevo postato questo codice:
    codice:
    Private Declare Function GetVersionExA Lib "Kernel32" (lpVersionInformation As OSVERSIONINFO) As Long
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type
    Public Enum Enum_OperatingPlatform
      Platform_Windows_32 = 0
      Platform_Windows_95_98_ME = 1
      Platform_Windows_NT_2K_XP = 2
    End Enum
    Public Enum Enum_OperatingSystem
      System_Windows_32 = 0
      System_Windows_95 = 1
      System_Windows_98 = 2
      System_Windows_ME = 3
      System_Windows_NT = 4
      System_Windows_2K = 5
      System_Windows_XP = 6
    End Enum
    Public Function OperatingPlatform() As Enum_OperatingPlatform
        Dim lpVersionInformation As OSVERSIONINFO
        lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
        Call GetVersionExA(lpVersionInformation)
        OperatingPlatform = lpVersionInformation.dwPlatformId
    End Function
    Public Function OperatingSystem() As Enum_OperatingSystem
        Dim lpVersionInformation As OSVERSIONINFO
        lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
        Call GetVersionExA(lpVersionInformation)
        If (lpVersionInformation.dwPlatformId = Platform_Windows_32) Then
            OperatingSystem = System_Windows_32
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 0) Then
            OperatingSystem = System_Windows_95
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 10) Then
            OperatingSystem = System_Windows_98
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 90) Then
            OperatingSystem = System_Windows_ME
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion < 5) Then
            OperatingSystem = System_Windows_NT
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 0) Then
            OperatingSystem = System_Windows_2K
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 1) Then
            OperatingSystem = System_Windows_XP
        End If
    End Function
    Che richiamavo in una status bar così:
    codice:
        Me.sb.Panels(3).Text = OperatingSystem
    Anche qui avevo apportato delle modifiche ma purtroppo senza successo.Ora mi chiedevo perchè?naturalmente non ho incluso le mie modifiche lasciando solo il codice originale in modo tale che qualcuno possa divertirsi a farlo funzionare!


    Mentre ora utilizzando questo funziona.
    codice:
    '-----Dichiarare in un form con command button--------
    
    Option Explicit
    Const VER_PLATFORM_WIN32_VISTA = 2
    Const VER_PLATFORM_WIN32_XP = 3
    Const VER_PLATFORM_WIN32_NT = 6
    Const VER_PLATFORM_WIN32_WINDOWS = 1
    Const VER_PLATFORM_WIN32s = 0
    
    Private Sub Command1_Click()
    Dim OS As OSVERSIONINFO
    OS.dwOSVersionInfoSize = Len(OS)
    GetVersionEx OS
    
    If OS.dwMajorVersion < 4 Then
    MsgBox "Impossibile continuare! E' richiesto Win 9x o WinNt 4.x", vbInformation
    End
    Else
    Select Case OS.dwPlatformId
    Case VER_PLATFORM_WIN32_WINDOWS
    MsgBox "Windows 95" & Str(OS.dwMajorVersion) & " Build " & Str(OS.dwBuildNumber), vbInformation
    Case VER_PLATFORM_WIN32_NT
    MsgBox "Windows NT Versione" & Str(OS.dwMajorVersion) & " Build " & Str(OS.dwBuildNumber), vbInformation
    Case VER_PLATFORM_WIN32_XP
    MsgBox "Windows XP Versione" & Str(OS.dwMajorVersion) & " Build " & Str(OS.dwBuildNumber), vbInformation
    Case VER_PLATFORM_WIN32_VISTA
    MsgBox "Windows Vista Ultimate Versione" & Str(OS.dwMajorVersion) & " Build " & Str(OS.dwBuildNumber), vbInformation
    End Select
    End If
    
    End Sub
    
    '------Dichiarare in modulo.bas--------
    
    Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    
    Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    End Type
    In questo modo funziona,gli ho fatto qualche modifica,che si può tranquillamente vedere in ogni punto in cui c'è scritto vista, così da renderlo aggiornato al nuovo sistema operativo.
    Ciao

  2. #2
    Mah.... il codice mi restituisce:
    Vista Ultimate Versione 5 Build 2600
    ma io ho XP Home !


    ...e un semplice Debug.Print Environ$("OS")
    cosa ti restituisce su Vista ?
    IceCube_HT (VB6 fan Club)

  3. #3
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480

    Re: [VB6]Rilevare versione di Windows

    Bastava modificare opportunamente la prima versione del codice

    codice:
    Private Declare Function GetVersionExA Lib "Kernel32" (lpVersionInformation As OSVERSIONINFO) As Long
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type
    Public Enum Enum_OperatingPlatform
      Platform_Windows_32 = 0
      Platform_Windows_95_98_ME = 1
      Platform_Windows_NT_2K_XP = 2
    End Enum
    Public Enum Enum_OperatingSystem
      System_Windows_32 = 0
      System_Windows_95 = 1
      System_Windows_98 = 2
      System_Windows_ME = 3
      System_Windows_NT = 4
      System_Windows_2K = 5
      System_Windows_XP = 6
      System_Windows_VISTA = 7
    End Enum
    Public Function OperatingPlatform() As Enum_OperatingPlatform
        Dim lpVersionInformation As OSVERSIONINFO
        lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
        Call GetVersionExA(lpVersionInformation)
        OperatingPlatform = lpVersionInformation.dwPlatformId
    End Function
    Public Function OperatingSystem() As Enum_OperatingSystem
        Dim lpVersionInformation As OSVERSIONINFO
        lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
        Call GetVersionExA(lpVersionInformation)
        If (lpVersionInformation.dwPlatformId = Platform_Windows_32) Then
            OperatingSystem = System_Windows_32
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 0) Then
            OperatingSystem = System_Windows_95
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 10) Then
            OperatingSystem = System_Windows_98
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 90) Then
            OperatingSystem = System_Windows_ME
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion < 5) Then
            OperatingSystem = System_Windows_NT
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 0) Then
            OperatingSystem = System_Windows_2K
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 1) Then
            OperatingSystem = System_Windows_XP
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 6) Then
            OperatingSystem = System_Windows_VISTA
        End If
    End Function
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  4. #4
    Utente di HTML.it L'avatar di rs125
    Registrato dal
    May 2008
    Messaggi
    193

    Re: Re: [VB6]Rilevare versione di Windows

    Originariamente inviato da oregon
    Bastava modificare opportunamente la prima versione del codice

    codice:
    Private Declare Function GetVersionExA Lib "Kernel32" (lpVersionInformation As OSVERSIONINFO) As Long
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type
    Public Enum Enum_OperatingPlatform
      Platform_Windows_32 = 0
      Platform_Windows_95_98_ME = 1
      Platform_Windows_NT_2K_XP = 2
    End Enum
    Public Enum Enum_OperatingSystem
      System_Windows_32 = 0
      System_Windows_95 = 1
      System_Windows_98 = 2
      System_Windows_ME = 3
      System_Windows_NT = 4
      System_Windows_2K = 5
      System_Windows_XP = 6
      System_Windows_VISTA = 7
    End Enum
    Public Function OperatingPlatform() As Enum_OperatingPlatform
        Dim lpVersionInformation As OSVERSIONINFO
        lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
        Call GetVersionExA(lpVersionInformation)
        OperatingPlatform = lpVersionInformation.dwPlatformId
    End Function
    Public Function OperatingSystem() As Enum_OperatingSystem
        Dim lpVersionInformation As OSVERSIONINFO
        lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
        Call GetVersionExA(lpVersionInformation)
        If (lpVersionInformation.dwPlatformId = Platform_Windows_32) Then
            OperatingSystem = System_Windows_32
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 0) Then
            OperatingSystem = System_Windows_95
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 10) Then
            OperatingSystem = System_Windows_98
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 90) Then
            OperatingSystem = System_Windows_ME
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion < 5) Then
            OperatingSystem = System_Windows_NT
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 0) Then
            OperatingSystem = System_Windows_2K
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 1) Then
            OperatingSystem = System_Windows_XP
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 6) Then
            OperatingSystem = System_Windows_VISTA
        End If
    End Function

    Anche io l'avevo modificato così e mi dice windows xp su vista però!sai perchè?

    Per quanto riguarda icecube_HT, in quel codice c'è un errore e non va nemmeno...me ne sono accorto dopo un pò di utilizzi!!Anche a me su xp dice vista!Ora vedo di correggerlo.
    Ciao

  5. #5
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    No ... a me su VISTA, ritorna il valore corretto ...

    Come chiami il codice? Come ti accorgi che indica "XP"?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  6. #6
    Utente di HTML.it L'avatar di rs125
    Registrato dal
    May 2008
    Messaggi
    193
    A me dice Xp su Vista ultimate con sp1. Aspetta che ti posto il codice con il quale lo richiamo.

    codice:
    .....
     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 1) Then
            OperatingSystem = System_Windows_XP
            frmMain.sb.Panels(3).Text = "Windows XP" 'Passo il risultato all'MDIForm
        ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 6) And (lpVersionInformation.dwMinorVersion = 1) Then
            OperatingSystem = System_Windows_VISTA
            frmMain.sb.Panels(3).Text = "Windows VISTA" 'Passo il risultato all'MDIForm
    In pratica ho dichiarato tutto in un modulo .bas e avendo una status bar gli passo il risultato direttamente dal modulo .bas all'evento form_load, facendo così:
    codice:
    frmMain.sb.Panels(3).Text = "Windows XP"
    frmMain.sb.Panels(3).Text = "Windows Vista"   'Questo l'ho messo per vedere se funziona.
    Ciao

  7. #7
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Fai attenzione ... non mi pare di averti detto che ci vuole la parte segnata in rosso ...

    codice:
    ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 6) And (lpVersionInformation.dwMinorVersion = 1) Then
    Se fai attenzione, nel codice che ti ho suggerito, quella parte non c'e' ...

    Questo fatto mi suggerisce l'ipotesi che tu aggiunga pezzi di codice senza esaminarli e capirli ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  8. #8
    Utente di HTML.it L'avatar di rs125
    Registrato dal
    May 2008
    Messaggi
    193
    Originariamente inviato da oregon
    Fai attenzione ... non mi pare di averti detto che ci vuole la parte segnata in rosso ...

    codice:
    ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 6) And (lpVersionInformation.dwMinorVersion = 1) Then
    Se fai attenzione, nel codice che ti ho suggerito, quella parte non c'e' ...

    Questo fatto mi suggerisce l'ipotesi che tu aggiunga pezzi di codice senza esaminarli e capirli ...
    No,scusami...ma ho copiato quel pezzo da un vecchio esempio che avevo fatto per prova e ho tolto tutto tranne quel pezzo(non l'ho visto). Io infatti lo eseguo senza quello ma non mi funziona proprio. Come mai??
    Ciao

  9. #9
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Originariamente inviato da rs125
    No,scusami...ma ho copiato quel pezzo da un vecchio esempio che avevo fatto per prova e ho tolto tutto tranne quel pezzo(non l'ho visto). Io infatti lo eseguo senza quello
    Che vuoi dire? Non capisco ...

    In definitiva ... quale codice usi?

    ma non mi funziona proprio. Come mai??
    Scusa ... ma come faccio a rispondere a questa tua domanda, dato che a me il codice funzione perfettamente?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  10. #10
    Utente di HTML.it L'avatar di rs125
    Registrato dal
    May 2008
    Messaggi
    193
    Originariamente inviato da oregon
    Che vuoi dire? Non capisco ...

    In definitiva ... quale codice usi?



    Scusa ... ma come faccio a rispondere a questa tua domanda, dato che a me il codice funzione perfettamente?
    Allora...mi spiego bene.In definitiva uso il codice che hai postato tu,quello corretto. Però mi dice che ho windows Xp.E' strano!mi dice che la vesione del windows è la 6 e di conseguenza mi da Windows Xp.Non riesco a capire perchè!
    Ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.