IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Déterminer version windows 10


Sujet :

VBScript

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Novembre 2017
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Déterminer version windows 10
    Bonjour,

    J'ai essayé de modifier un script trouver ici pour tester si l'OS est windows 10.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    If FindOSType(".") = "Windows 10" Then 
    MsgBox "Exécution avec Windows 10",64,"Système d'exploitation"
    'votre code pour Windows 10
    Else
    MsgBox "Exécution avec Windows 7",64,"Système d'exploitation"
    'Votre code pour les autres systèmes
    end if
     
    Function FindOSType(strComputer)
    'Defining Variables
        Dim objWMI, objItem, colItems
        Dim OSVersion, OSName, ProductType
     
    'Get the WMI object and query results
        Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
        Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
     
    'Get the OS version number (first two) and OS product type (server or desktop) 
        For Each objItem in colItems
            OSVersion = Left(objItem.Version,3)
            ProductType = objItem.ProductType
        Next
    'Time to convert numbers into names
        Select Case OSVersion
        Case "10.0*"    
    		OSName = "Windows 10"
        Case "6.1"
            OSName = "Windows 7"
        End Select
     
    'Return the OS name
        FindOSType = OSName
     
    'Clear the memory
        Set colItems = Nothing
        Set objWMI = Nothing
    End Function
    Malheureusement cela ne fonctionne pas. Pourriez-vous m'aider ?

    Je vous remercie par avance

  2. #2
    Modérateur
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 077
    Points : 17 170
    Points
    17 170
    Par défaut
    Salut zab31, bienvenue sur DVP

    Malheureusement cela ne fonctionne pas.
    Un peu court comme descriptif de ton problème.

    Malgré tout, essais de mettre momentanément un MsgBox dans ta fonction pour vérifier se que contient ta variable OSVersion
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        Next
    'Time to convert numbers into names
        MsgBox OSVersion
        Select Case OSVersion
    Car il n'est pas dit que ton Windows 10 ai la version "10.0*" de ton Case
    Soyez sympa, pensez -y
    Balises[CODE]...[/CODE]
    Balises[CODE=NomDuLangage]...[/CODE] quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Balises[C]...[/C] code intégré dans une phrase.
    Balises[C=NomDuLangage]...[/C] code intégré dans une phrase quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Le bouton en fin de discussion, quand vous avez obtenu l'aide attendue.
    ......... et pourquoi pas, pour remercier, un pour celui/ceux qui vous ont dépannés.
    👉 → → Ma page perso sur DVP ← ← 👈

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Novembre 2017
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Merci beaucoup avec l'info du Msgbox j'ai pu corrigé le script

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    If FindOSType(".") = "Windows 10" Then 
    MsgBox "Exécution avec Windows 10",64,"Système d'exploitation"
    'votre code pour Windows 10
    Else
    MsgBox "Exécution avec Windows 7",64,"Système d'exploitation"
    'Votre code pour les autres systèmes
    end if
     
    Function FindOSType(strComputer)
    'Defining Variables
        Dim objWMI, objItem, colItems
        Dim OSVersion, OSName, ProductType
     
    'Get the WMI object and query results
        Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
        Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
     
    'Get the OS version number (first two) and OS product type (server or desktop) 
        For Each objItem in colItems
            OSVersion = Left(objItem.Version,3)
            ProductType = objItem.ProductType
        Next
    'Time to convert numbers into names
    	Select Case OSVersion
        Case "10."    
    		OSName = "Windows 10"
        Case "6.1"
            OSName = "Windows 7"
        End Select
     
    'Return the OS name
        FindOSType = OSName
     
    'Clear the memory
        Set colItems = Nothing
        Set objWMI = Nothing
    End Function
    Faut dire que je suis un newbee ^^

  4. #4
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 184
    Points : 5 755
    Points
    5 755
    Par défaut
    Je propose un autre code plus simple et complet qui pourra peut être servir à d'autre.

    Code vbs : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    OsName = GetShortOsName()
    If OsName = "Windows 10" Then 
    	MsgBox "Exécution avec " & OsName, 64, "Système d'exploitation"
    	' Votre code pour Windows 10
    Else
    	MsgBox "Exécution avec " & OsName, 64, "Système d'exploitation"
    	' Votre code pour les autres systèmes
    End If
     
    Function GetShortOsName()
    	' https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms724832(v=vs.85).aspx
    	' https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
    	' http://www.nogeekleftbehind.com/2013/09/10/updated-list-of-os-version-queries-for-wmi-filters/
     
    	For Each objItem in GetObject("winmgmts://./root/cimv2").ExecQuery("Select * from Win32_OperatingSystem",,48)
    		version = objItem.Version
    		ProductType = objItem.ProductType
    	Next
     
    	Select Case Left(version, Instr(version, ".") + 1)
    	Case "10.0"
    		If (ProductType = "1") Then
    			GetShortOsName = "Windows 10"
    		Else
    			GetShortOsName = "Windows Server 2016"
    		End If
    	Case "6.3"
    		If (ProductType = "1") Then
    			GetShortOsName = "Windows 8.1"
    		Else
    			GetShortOsName = "Windows Server 2012 R2"
    		End If
    	Case "6.2"
    		If (ProductType = "1") Then
    			GetShortOsName = "Windows 8"
    		Else
    			GetShortOsName = "Windows Server 2012"
    		End If
    	Case "6.1"
    		If (ProductType = "1") Then
    			GetShortOsName = "Windows 7"
    		Else
    			GetShortOsName = "Windows Server 2008 R2"
    		End If
    	Case "6.0"
    		If (ProductType = "1") Then
    			GetShortOsName = "Windows Vista"
    		Else
    			GetShortOsName = "Windows Server 2008"
    		End If
    	Case "5.2"
    		If (ProductType = "1") Then
    			GetShortOsName = "Windows XP 64-Bit Edition"
    		ElseIf (Left(Version, 5) = "5.2.3") Then
    			GetShortOsName = "Windows Server 2003 R2"
    		Else
    			GetShortOsName = "Windows Server 2003"
    		End If
    	Case "5.1"
    		GetShortOsName = "Windows XP"
    	Case "5.0"
    		GetShortOsName = "Windows 2000"
    	End Select
    End Function

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Novembre 2017
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Avec beaucoup de retard... Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 01/02/2009, 19h05
  2. Format date et version windows
    Par ZIED dans le forum Delphi
    Réponses: 3
    Dernier message: 06/12/2006, 09h05
  3. Version Windows x64 x86 ?
    Par warwink dans le forum Windows XP
    Réponses: 9
    Dernier message: 09/06/2006, 01h53
  4. Version windows de PostGreSQL
    Par BONNEFOI Patrick dans le forum PostgreSQL
    Réponses: 5
    Dernier message: 04/09/2003, 08h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo