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

C++Builder Discussion :

Probleme de transtypage lors de l'utilisation de WMI [Système/Fichiers/API]


Sujet :

C++Builder

  1. #1
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut Probleme de transtypage lors de l'utilisation de WMI
    Bonjours
    Je tente d'utiliser WMI a l'aide de la FAQ Delphi et de deux articles egalement en Delphi
    Il y a cependant un transtypage que je n'arrive pas a realiser voici un extrait du Tuto
    Une fois une collection récupérée, on utilise une interface IEnumVariant qui implémente des fonctions d’énumération sur des données de type variant.
    Elle nécessite le transtypage suivant sur un objet de type collection, ici WmiObjectSet :

    ObjectEnumerator:= (WmiObjectSet._NewEnum) as IEnumVariant;
    La méthode .Next permet une itération pour un ou plusieurs éléments. Elle renvoie S_OK tant qu’il reste des éléments à extraire.
    L’élément récupéré de type OleVariant doit à son tour être transtypé pour permettre de le manipuler correctement :

    WmiObject := IUnknown(ArrayVariant) as SWBemObject;
    Ici l’objet ArrayVariant est transtypé vers la variable WmiObject de type SWBemObject.
    On peut ensuite utiliser les propriétés et méthodes de la variable WmiObject .
    Le transtypage de l’élément récupéré doit correspondre au type d’objet de la collection, par exemple pour une variable WmiProperty de type SWBemProperty :
    WmiProperty:=IUnknown(ArrayVariant) as SWBemProperty;
    Voici le morceau de code que je n'arrive pas a transtyper
    WmiProperty:=IUnknown(ArrayVariant) as SWBemProperty;
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  2. #2
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Voici comment j'ai commence a tester
    J'ai ajoute les composants conformement au Tuto
    dans le source j'ai ajoute
    #pragma link "WbemScripting_OCX"
    #pragma link "WMIEXTENSIONLib_OCX"
    et
    #include "WbemScripting_OCX.h"
    #include "WMIEXTENSIONLib_OCX.h"
    #include <OleServer.hpp>
    le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    SWbemProperty *WmiProperty;
    String CreationTime;
     
    // code que je n'arrive pas atranstyper
    // WmiProperty = IUnknown(ArrayVariant) as SWBemProperty;
     
      TSWbemDateTime *WmiDateTime = new TSWbemDateTime(NULL);
      WmiProperty->Name = "CreationTime";
    }
    Voici le lien sur le code Delphi
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  3. #3
    Membre expérimenté
    Avatar de sat83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2004
    Messages
    1 040
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2004
    Messages : 1 040
    Points : 1 307
    Points
    1 307
    Par défaut
    Je ne connais pas du tout WMI, et je suppose qu'un simple transtypage ne fonctionne pas?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    //WmiProperty := IUnknown(ArrayVariant) as SWBemProperty;
    WmiProperty = (SWBemProperty*) IUnknown(ArrayVariant);
    //ou
    WmiProperty = (SWBemProperty*) ((IUnknown)ArrayVariant);
    Ce que l'on apprend par l'effort reste toujours ancré plus longtemps...

  4. #4
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci pour ta reponse sat83
    Je viens de tester ta solution mais il ne reconnais pas
    ArrayVariant
    J'ai regarde dans l'aide BCB apparament c'est specifique a Delphi, j'ai inclu " #include "Unknwn.h "
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  5. #5
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut
    en principe le transtypage <as> de delphi est équivaleent en c++builder avec un reinterpret_cast

    ci-joint un exemple qui utilise directement les api MS
    le .h
    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
     
    //---------------------------------------------------------------------------
     
    #ifndef UWmiSampleH
    #define UWmiSampleH
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <Wbemidl.h>
    //---------------------------------------------------------------------------
    class TForm45 : public TForm
    {
    __published:	// Composants gérés par l'EDI
    	TMemo *Memo1;
    	TButton *Button1;
    	void __fastcall Button1Click(TObject *Sender);
    private:	// Déclarations utilisateur
    	HRESULT hres;
    	IWbemLocator *pLoc;
    	IWbemServices *pSvc;
    	IEnumWbemClassObject* pEnumerator;
     
    public:		// Déclarations utilisateur
    	__fastcall TForm45(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm45 *Form45;
    //---------------------------------------------------------------------------
    #endif
    et le code
    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
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
     
    //---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "UWmiSample.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm45 *Form45;
    //---------------------------------------------------------------------------
    __fastcall TForm45::TForm45(TComponent* Owner)
    	: TForm(Owner),
    	pLoc(0),
    	pSvc(0),
    	pEnumerator(0)
     
    {
     //	hres = CoInitialize(NULL);
    	// Initialize COM.   	hres =  CoInitializeEx(0, COINIT_MULTITHREADED);
     
     
     
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm45::Button1Click(TObject *Sender)
    {
       hres= CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
       if(FAILED(hres))
    	  {
    	   MessageDlg("Failed to initialize COM. Error code = 0x"+IntToHex((int)hres,8), mtError, TMsgDlgButtons() << mbOK, 0);
    	   CoUninitialize();
    	  return;
    	  }
       hres =  CoInitializeSecurity(
    		NULL,
    		-1,                          // COM authentication
    		NULL,                        // Authentication services
    		NULL,                        // Reserved
    		RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
    		RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
    		NULL,                        // Authentication info
    		EOAC_NONE,                   // Additional capabilities
    		NULL                         // Reserved
    		);
    	if(FAILED(hres))
    	  {
    	   MessageDlg("Failed to initialize security. Error code = 0x"+IntToHex((int)hres,8), mtError, TMsgDlgButtons() << mbOK, 0);
    	  CoUninitialize();
    	  return;
    	  }
       hres = CoCreateInstance(CLSID_WbemLocator, 0,
    		CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
     
    	if (FAILED(hres))
    	   {
    		MessageDlg("WMI Access Error 0x"+IntToHex((int)hres,8), mtError, TMsgDlgButtons() << mbOK, 0);
    		CoUninitialize();
    		return;
    	   }
    	hres = pLoc->ConnectServer(
    		 L"ROOT\\CIMV2", // Object path of WMI namespace
    		 NULL,                    // User name. NULL = current user
    		 NULL,                    // User password. NULL = current
    		 0,                       // Locale. NULL indicates current
    		 NULL,                    // Security flags.
    		 0,                       // Authority (e.g. Kerberos)
    		 0,                       // Context object
    		 &pSvc                    // pointer to IWbemServices proxy
    		 );
     
    	if (FAILED(hres))
    	  {
    	   MessageDlg("WMI Server Access Error 0x"+IntToHex((int)hres,8), mtError, TMsgDlgButtons() << mbOK, 0);
    		pLoc->Release();
    		CoUninitialize();
     
    		return;
     
    	  }
    	  hres = CoSetProxyBlanket(
     
    	   pSvc,                         // the proxy to set
    	   RPC_C_AUTHN_WINNT,            // authentication service
    	   RPC_C_AUTHZ_NONE,             // authorization service
    	   NULL,                         // Server principal name
    	   RPC_C_AUTHN_LEVEL_CALL,       // authentication level
    	   RPC_C_IMP_LEVEL_IMPERSONATE,  // impersonation level
    	   NULL,                         // client identity
    	   EOAC_NONE                     // proxy capabilities
    	);
    	if (FAILED(hres))
    	  {
    	   MessageDlg("WMI Server Access Error 0x"+IntToHex((int)hres,8), mtError, TMsgDlgButtons() << mbOK, 0);
           	pLoc->Release();
    		CoUninitialize();
    	   return;
    	   }
    	   hres = pSvc->ExecQuery(
    		L"WQL",
    		L"SELECT * FROM Win32_Process",
    		WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
    		NULL,
    		&pEnumerator);
     
    	if (FAILED(hres))
    	{
    		 MessageDlg("Query failed. Error code = 0x"+IntToHex((int)hres,8), mtError, TMsgDlgButtons() << mbOK, 0);
    		 pSvc->Release();
    		 pLoc->Release();
    		CoUninitialize();
    		return ;               // Program has failed.
    	}
     
    	// Step 7: -------------------------------------------------
    	// Get the data from the query in step 6 -------------------
    	IWbemClassObject *pclsObj;
    	ULONG uReturn = 0;
    	   while (pEnumerator)
    	{
    		HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
    			&pclsObj, &uReturn);
     
    		if(0 == uReturn)
    		{
    			break;
    		}
     
    		VARIANT vtProp;
     
    		// Get the value of the Name property
    		hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
    		Memo1->Lines->Add("Process Name: "+UnicodeString(vtProp.bstrVal));
    		VariantClear(&vtProp);
    	}
       pSvc->Release();
       pLoc->Release();
       CoUninitialize();
     
    }
    //---------------------------------------------------------------------------
    sur la forme j'ai déposé un composant TMemo pour afficger les résultats de la requête(Win32_Process) ainsi qu'un bouton pour lancer la procédure
    cordialement
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  6. #6
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci pour ta reponse DjmSoftware
    J'ai teste ton exemple apres ajout de " wbemuuid.lib " dans le repertoire du projet, cela fonctionne parfaitement.
    Je ne suis pas famillie de ce genre de code, j'ai du mal a comprendre son fonctionnement
    Pour mon probleme de transtypage j'ai essaye ceci sans succes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    vWmiProperty = reinterpret_cast<IUnknown(ArrayVariant)> (SWbemProperty);
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  7. #7
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut Blondelle
    La syntaxe est la suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
      WmiProperty=reinterpret_cast<SWbemProperty*>((IUnknown*)ArrayVariant);
    en delphi les variables sont passées par référence --> utilisation de la VCL sous c++ Builder avec des pointeurs

    Je te conseille malgré tout d'utiliser en c++ les Api de MS
    Cordialement
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  8. #8
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci DjmSoftware
    Je n'aurais pas trouve, je suis d'accord avec toi pour l'utilisation des Api, j'essaie juste de traduire la FAQ Delphi sur le sujet, dur dur!!!!
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  9. #9
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Je viens de tester et j'ai une erreur
    [C++ Error] Unit1.cpp(29): E2451 Undefined symbol 'ArrayVariant'
    Il doit me manquer une definition de 'ArrayVariant', ce n'est pas dans l'aide C++ Builder et Delphi
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  10. #10
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut Blondelle
    pour la FAQ inspire toi des exemples fournis par MS dans MSDN
    tu trouveras également chez Borland plusieurs choses a ce sujet par exemple


    Il ya également une FAQ
    http://edn.embarcadero.com/search?q=...rds=y&x=12&y=1

    Cordialement
    Fichiers attachés Fichiers attachés
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  11. #11
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut
    ArrayVariant c'est le nom de la variable le type est OleVAriant
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  12. #12
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci DjmSoftware
    Pour ton aide et les liens, je vois tous cela ce soir
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  13. #13
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Hello Blondelle
    tu trouveras ci-dessous un exemple de programme retournant des informations sur le BIOS via l'API WMI
    j'ai modifié un exemple réalisé à l'époque sous C++ Builder5
    je n'utilise ici que des variants
    j'ai compilé ce code sous RadStudio 2010 il me semble que l'implémentation des variants aie changé depuis c++ Builder 6
    code pour c++ Builder 6:
    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
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
     
    //---------------------------------------------------------------------------
    #include <comobj.hpp>
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
     
     
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
     
    }
     
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    Close();        
    }
    //---------------------------------------------------------------------------
     
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    Button1->Enabled=false;
    //Connect to SWbemLocator:
    Variant locator = Variant::CreateObject("WbemScripting.SWbemLocator");
    if(locator.IsNull())
            {
    		 ShowMessage("Could not connect to SWbemLocator");
    		 Application->Terminate();
    	   }
     
    //Get SWbemServices
    Variant srv=locator.OleFunction("ConnectServer");
    if(srv.IsNull())
    		{
    		 ShowMessage("Could not connect to SWbemServices");
    		  Application->Terminate();
    		}
     
    //Setting security attributes
     
    Variant Secure=srv.OlePropertyGet("Security_");
    if(Secure.IsNull())
    		{
    		 ShowMessage("Could not get Security_ property of SWbemServices");
    		 Application->Terminate();
    		}
     
    //Set ImpersonationLevel in wbemImpersonationLevelImpersonate
    Secure.OlePropertySet("ImpersonationLevel" , 3);
     
    //Method InstancesOf creates an enumerator that returns the instances of a
    //specified class according to user-specified selection criteria (Win32_BIOS)
    Variant WbemBIOS=srv.OleFunction("InstancesOf","Win32_BIOS");
    if(WbemBIOS.IsNull())
    		{
    		 ShowMessage("Could not get instance Win32_BIOS enumerator");
    		 Application->Terminate();
    		}
     
    //How much object in the collection:
     
    int lcount=WbemBIOS.OlePropertyGet("Count");
     
    // int lcount=WbemBIOS.Exec(PropertyGet("count"));
    if(lcount != 1)
    		{
    		 ShowMessage("Only one instance!");
    		 Application->Terminate();
    		}
     
    	VARIANT BIOS;
    	LPUNKNOWN punkEnum=0;
    	IEnumVARIANT * penum=NULL;
    	int nIndex;
     
    	unsigned long cc;
     
    //Prepare for enumerate
    	punkEnum =WbemBIOS.OlePropertyGet("_NewEnum");
    	punkEnum->QueryInterface(IID_IEnumVARIANT, (LPVOID FAR*)&penum);
    	penum->AddRef();
    	punkEnum->Release();
     
    	VariantInit(&BIOS);
    	//Get object:
    	penum->Next(1,&BIOS,&cc);
    	if(BIOS.vt==0)
    		{
    		 ShowMessage("No instance of Win32_BIOS class");
    		 Application->Terminate();
    		}
       // penum->Release(); //free interface
     
    	  Variant result;
              Variant tmp(&BIOS);
     
    //Obtaining properties of Win32_BIOS instance:
    	 result=tmp.OlePropertyGet("Caption");
    	 if(!result.IsNull())Edit1->Text=result;
     
    	  result=tmp.OlePropertyGet("Name");
    	  if(!result.IsNull())Edit2->Text=result;
     
    	  result=tmp.OlePropertyGet("Description");
    	  if(!result.IsNull())Edit5->Text=result;
     
    	  result=tmp.OlePropertyGet("Manufacturer");
          if(!result.IsNull())Edit6->Text=result;
     
    	  result=tmp.OlePropertyGet("SerialNumber");
    	  if(!result.IsNull())Edit7->Text=result;
     
    	  result=tmp.OlePropertyGet("Status");
          if(!result.IsNull())Edit8->Text=result;
     
    	  result=tmp.OlePropertyGet("Version");
          if(!result.IsNull())Edit9->Text=result;
     
    	  result=tmp.OlePropertyGet("CurrentLanguage");
          if(!result.IsNull())Edit10->Text=result;
     
    	  VariantClear(&BIOS);
              tmp=Unassigned();
    	  result=Unassigned();
    	  Button1->Enabled=false;
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::FormDeactivate(TObject *Sender)
    {
    CoUninitialize();
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::Button3Click(TObject *Sender)
    {
    Form2->ShowModal();
    }
    //---------------------------------------------------------------------------
    ce code est parfaitement fonctionnel sous c++ Builder6 mais provoque des violations d'accès sous RadStudio

    cordialement
    Fichiers attachés Fichiers attachés
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  14. #14
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Points : 713
    Points
    713
    Par défaut
    pour ma part , j utilise ce code à la base , puis le modifie lorsque j ai besoin de toucher de WMI

    .h
    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
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    //---------------------------------------------------------------------------
     
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <CheckLst.hpp>
    #include <ComCtrls.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:	// Composants gérés par l'EDI
            TButton *tbSysCheckShow;
            TButton *buSystemCheckPeriph;
            TButton *buSystemCheckActu;
            TCheckBox *SystemCheckActu;
            TListBox *lbSystemCheck;
            TCheckListBox *clbSystemCheck;
            TProgressBar *pbSystemCheck;
            TCheckBox *cbActuAuto;
            void __fastcall tbSysCheckShowClick(TObject *Sender);
            void __fastcall buSystemCheckPeriphClickClick(TObject *Sender);
            void __fastcall buSystemCheckActuClickClick(TObject *Sender);
            void __fastcall SystemCheckActuClickClick(TObject *Sender);
            void __fastcall FormCreate(TObject *Sender);
            void __fastcall Button1Click(TObject *Sender);
    private:	// Déclarations de l'utilisateur
    public:		// Déclarations de l'utilisateur
     
     
     
     // Information Détaillées du Systeme par WMI [System Check]
    void GetWmiInfo(TStrings *lpList, WideString wsClass)
    {
      IWbemLocator *pWbemLocator = NULL;
      if(CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pWbemLocator) == S_OK)
      {
        IWbemServices *pWbemServices = NULL;
        WideString wsNamespace = (L"root\\cimv2");
        if(pWbemLocator->ConnectServer(wsNamespace, NULL, NULL, NULL, 0, NULL, NULL, &pWbemServices) == S_OK)
        {
          IEnumWbemClassObject *pEnumClassObject = NULL;
          WideString wsWQL=L"WQL", wsQuery=WideString(L"Select * from ")+wsClass;
          if(pWbemServices->ExecQuery(wsWQL, wsQuery, WBEM_FLAG_RETURN_IMMEDIATELY,NULL, &pEnumClassObject) == S_OK)
          {
            IWbemClassObject *pClassObject = NULL;
            ULONG uCount = 1, uReturned;
            if(pEnumClassObject->Reset() == S_OK)
            {
              while(pEnumClassObject->Next(WBEM_INFINITE, uCount, &pClassObject, &uReturned) == S_OK)
              {
                SAFEARRAY *pvNames = NULL;
                if(pClassObject->GetNames(NULL, WBEM_FLAG_ALWAYS | WBEM_MASK_CONDITION_ORIGIN, NULL, &pvNames) == S_OK)
                {
                  long vbl, vbu;
                  SafeArrayGetLBound(pvNames, 1, &vbl);
                  SafeArrayGetUBound(pvNames, 1, &vbu);
                  for(long idx=vbl; idx<=vbu; idx++)
                  {
                    long aidx = idx;
                    wchar_t *wsName = 0;
                    VARIANT vValue;
                    VariantInit(&vValue);
                    SafeArrayGetElement(pvNames, &aidx, &wsName);
                    BSTR bs = SysAllocString(wsName);
                    HRESULT hRes = pClassObject->Get(bs, 0, &vValue, NULL, 0);
                    SysFreeString(bs);
                    if(hRes == S_OK)
                    {
                      AnsiString s;
                      Variant v = *(Variant*)&vValue;
                      if(v.IsArray())
                      {
                        for(int i=v.ArrayLowBound(); i<=v.ArrayHighBound(); i++)
                        {
                          Variant a = v.GetElement(i);
                          if(!s.IsEmpty())
                            s+=", ";
                            s+=VarToStr(a);
                        }
                      }
                      else
                      {
                        s = VarToStr(v);
                      }
                      lpList->Add(AnsiString(wsName)+"="+s);
                    }
                  VariantClear(&vValue);
                  SysFreeString(wsName);
                  }
                }
                if(pvNames)SafeArrayDestroy(pvNames);
              }
            }
            if(pClassObject)pClassObject->Release();
          }
          if(pEnumClassObject)pEnumClassObject->Release();
        }
        if(pWbemServices)pWbemServices->Release();
      }
      if(pWbemLocator)pWbemLocator->Release();
    }
     
     
     
     __fastcall TForm1(TComponent* Owner);
    };  
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif

    .cpp
    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
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    //---------------------------------------------------------------------------
     
    #include <vcl.h>
    #include <mmsystem.h>
    #include <winsock2.h>
    #include <StrUtils.hpp>
    #include <comdef.h>
    #include <wbemidl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
     
    int NbrRunUser;
    int NbrRunLocal;
    int ItemSelectV;
    int ItemSelectN;
    int ItemSelectC;
    int ClickSystemCheck = 0;
    int PeriphSystemCheck = 0;
    int NbrSystemCheck = 0;
     
    TStringList *SystemCheck = new TStringList();
     
     
     
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::tbSysCheckShowClick(TObject *Sender)
     
      {
      if(ClickSystemCheck == 0)
      {
        SystemCheck->Add("Win32_1394Controller");
        SystemCheck->Add("Win32_1394ControllerDevice");
        SystemCheck->Add("Win32_AllocatedResource");
        SystemCheck->Add("Win32_AssociatedBattery");
        SystemCheck->Add("Win32_AssociatedProcessor");
        SystemCheck->Add("Win32_AutochkSetting");
        SystemCheck->Add("Win32_BaseBoard");
        SystemCheck->Add("Win32_Battery");
        SystemCheck->Add("Win32_BIOS");
        SystemCheck->Add("Win32_Bus");
        SystemCheck->Add("Win32_CacheMemory");
        SystemCheck->Add("Win32_CDROMDrive");
        SystemCheck->Add("Win32_ControllerHasHub");
        SystemCheck->Add("Win32_CurrentProbe");
        SystemCheck->Add("Win32_DefragAnalysis");
        SystemCheck->Add("Win32_DesktopMonitor");
        SystemCheck->Add("Win32_DeviceBus");
        SystemCheck->Add("Win32_DeviceMemoryAdress");
        SystemCheck->Add("Win32_DeviceSettings");
        SystemCheck->Add("Win32_DiskDrive");
        SystemCheck->Add("Win32_DiskDrivePhysicalMedia");
        SystemCheck->Add("Win32_DisplayConfiguration");
        SystemCheck->Add("Win32_DisplayControllerConfiguration");
        SystemCheck->Add("Win32_DMAChannel");
        SystemCheck->Add("Win32_DriverForDevice");
        SystemCheck->Add("Win32_Fan");
        SystemCheck->Add("Win32_FloppyController");
        SystemCheck->Add("Win32_FloppyDrive");
        SystemCheck->Add("Win32_HeatPipe");
        SystemCheck->Add("Win32_IDEController");
        SystemCheck->Add("Win32_IDEControllerDevice");
        SystemCheck->Add("Win32_InfraredDevice");
        SystemCheck->Add("Win32_IRQRessource");
        SystemCheck->Add("Win32_Keyboard");
        SystemCheck->Add("Win32_MemoryArray");
        SystemCheck->Add("Win32_MemoryArrayLocation");
        SystemCheck->Add("Win32_MemoryDevice");
        SystemCheck->Add("Win32_MemoryDeviceArray");
        SystemCheck->Add("Win32_MemoryDeviceLocation");
        SystemCheck->Add("Win32_MotherboardDevice");
        SystemCheck->Add("Win32_MountPoint");
        SystemCheck->Add("Win32_NetworkAdapter");
        SystemCheck->Add("Win32_NetworkAdapterConfiguration");
        SystemCheck->Add("Win32_NetworkAdapterSetting");
        SystemCheck->Add("Win32_OnBoardDevice");
        SystemCheck->Add("Win32_ParallelPort");
        SystemCheck->Add("Win32_PCMCIAController");
        SystemCheck->Add("Win32_PhysicalMedia");
        SystemCheck->Add("Win32_PhysicalMemory");
        SystemCheck->Add("Win32_PhysicalMemoryArray");
        SystemCheck->Add("Win32_PhysicalMemoryLocation");
        SystemCheck->Add("Win32_PnPAllocatedResource");
        SystemCheck->Add("Win32_PnPDevice");
        SystemCheck->Add("Win32_PnPEntity");
        SystemCheck->Add("Win32_PnPSignedDriver");
        SystemCheck->Add("Win32_PnPSignedDriverCIMDataFile");
        SystemCheck->Add("Win32_PointingDevice");
        SystemCheck->Add("Win32_PortableBattery");
        SystemCheck->Add("Win32_PortConnector");
        SystemCheck->Add("Win32_PortRessource");
        SystemCheck->Add("Win32_PowerManagementEvent");
        SystemCheck->Add("Win32_POTSModem");
        SystemCheck->Add("Win32_POTSModemToSerialPort");
        SystemCheck->Add("Win32_Printer");
        SystemCheck->Add("Win32_PrinterConfiguration");
        SystemCheck->Add("Win32_PrinterController");
        SystemCheck->Add("Win32_PrinterDriver");
        SystemCheck->Add("Win32_PrinterDriverDll");
        SystemCheck->Add("Win32_PrinterSetting");
        SystemCheck->Add("Win32_PrintJob");
        SystemCheck->Add("Win32_Processor");
        SystemCheck->Add("Win32_Refrigeration");
        SystemCheck->Add("Win32_SCSIController");
        SystemCheck->Add("Win32_SCSIControllerDevice");
        SystemCheck->Add("Win32_SerialPort");
        SystemCheck->Add("Win32_SerialPortConfiguration");
        SystemCheck->Add("Win32_SerialPortSetting");
        SystemCheck->Add("Win32_SMBIOSMemory");
        SystemCheck->Add("Win32_SoundDevice");
        SystemCheck->Add("Win32_SystemBIOS");
        SystemCheck->Add("Win32_SystemDriverPnPEntity");
        SystemCheck->Add("Win32_SystemEnclosure");
        SystemCheck->Add("Win32_SystemMemoryResource");
        SystemCheck->Add("Win32_SystemSlot");
        SystemCheck->Add("Win32_TapeDrive");
        SystemCheck->Add("Win32_TCPIPPrinterPort");
        SystemCheck->Add("Win32_TemperatureProbe");
        SystemCheck->Add("Win32_UninterruptiblePowerSupply");
        SystemCheck->Add("Win32_USBController");
        SystemCheck->Add("Win32_USBControllerDevice");
        SystemCheck->Add("Win32_USBHub");
        SystemCheck->Add("Win32_VideoConfiguration");
        SystemCheck->Add("Win32_VideoController");
        SystemCheck->Add("Win32_VideoSettings");
        SystemCheck->Add("Win32_VoltageProbe");
     
        NbrSystemCheck = SystemCheck->Count;
     
        for(int NbrSystemCheckStrings = 0; NbrSystemCheckStrings<NbrSystemCheck; NbrSystemCheckStrings++)
        {
          AnsiString SystemCheckText = (SystemCheck->Strings[NbrSystemCheckStrings]);
          clbSystemCheck->Items->Add(AnsiReplaceText(SystemCheckText, "Win32_", " "));
        }
        ClickSystemCheck = 1;
      }
    }
     
    //---------------------------------------------------------------------------
    void __fastcall TForm1::buSystemCheckPeriphClickClick(TObject *Sender)
    {
      if(PeriphSystemCheck == 0)
      {
        lbSystemCheck->Clear();
        clbSystemCheck->Items->Clear();
        SendMessage(pbSystemCheck->Handle, PBM_SETBARCOLOR, 0, clTeal);
        pbSystemCheck->Visible = true;
        cbActuAuto->Visible = false;
        buSystemCheckActu->Visible = false;
        buSystemCheckPeriph->Visible = false;
        clbSystemCheck->Visible = false;
        lbSystemCheck->Visible = false;
     
        pbSystemCheck->Min = 0;
        pbSystemCheck->Max = NbrSystemCheck;
     
        for(int NbrSystemCheckStrings = 0; NbrSystemCheckStrings<NbrSystemCheck; NbrSystemCheckStrings++)
        {
          TStringList *SystemCheckViewClb = new TStringList();
          pbSystemCheck->Position = NbrSystemCheckStrings;
     
          if(pbSystemCheck->Position == NbrSystemCheck - 1)
          {
            pbSystemCheck->Visible = false;
            clbSystemCheck->Visible = true;
            lbSystemCheck->Visible = true;
            buSystemCheckActu->Visible = true;
            cbActuAuto->Visible = true;
          }
     
          GetWmiInfo(SystemCheckViewClb, SystemCheck->Strings[NbrSystemCheckStrings]);
          int NbrSystemCheckViewClb = SystemCheckViewClb->Count;
          if(NbrSystemCheckViewClb > 0)
          {
            AnsiString SystemCheckTextClb = (SystemCheck->Strings[NbrSystemCheckStrings]);
            clbSystemCheck->Items->Add(AnsiReplaceText(SystemCheckTextClb, "Win32_", " "));
          }
        }
        PeriphSystemCheck = 1;
      }        
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::buSystemCheckActuClickClick(TObject *Sender)
    {
      lbSystemCheck->Clear();
      for(int SystemChecked=0; SystemChecked<clbSystemCheck->Items->Count; SystemChecked++)
      {
        if(clbSystemCheck->Checked[SystemChecked])
        {
          TStringList *SystemCheckViewLb = new TStringList();
          AnsiString SystemCheckedWin32 = (clbSystemCheck->Items->Strings[SystemChecked]);
          GetWmiInfo(SystemCheckViewLb, AnsiReplaceText(SystemCheckedWin32, " ", "Win32_"));
          int NbrSystemCheckViewLb = SystemCheckViewLb->Count;
     
          if(NbrSystemCheckViewLb > 0)
          {
            lbSystemCheck->Items->Add("");
            lbSystemCheck->Items->Add("");
            lbSystemCheck->Items->Add("===============================[ " + SystemCheckedWin32 + " ]===============================");
            lbSystemCheck->Items->Add("");
            GetWmiInfo(lbSystemCheck->Items , AnsiReplaceText(SystemCheckedWin32, " ", "Win32_"));
          }
          else
          {
            lbSystemCheck->Items->Add("");
            lbSystemCheck->Items->Add("");
            lbSystemCheck->Items->Add("===============================[ " + SystemCheckedWin32 + " ]===============================");
            lbSystemCheck->Items->Add("- Peripherique pas pris en Charge");
          }
        }
      }        
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::SystemCheckActuClickClick(TObject *Sender)
    {
           if(cbActuAuto->Checked)
      {
        lbSystemCheck->Clear();
        for(int SystemChecked=0; SystemChecked<clbSystemCheck->Items->Count; SystemChecked++)
        {
          if(clbSystemCheck->Checked[SystemChecked])
          {
            TStringList *SystemCheckViewLb = new TStringList();
            AnsiString SystemCheckedWin32 = (clbSystemCheck->Items->Strings[SystemChecked]);
            GetWmiInfo(SystemCheckViewLb, AnsiReplaceText(SystemCheckedWin32, " ", "Win32_"));
            int NbrSystemCheckViewLb = SystemCheckViewLb->Count;
     
            if(NbrSystemCheckViewLb > 0)
            {
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("===============================[ " + SystemCheckedWin32 + " ]===============================");
              lbSystemCheck->Items->Add("");
              GetWmiInfo(lbSystemCheck->Items , AnsiReplaceText(SystemCheckedWin32, " ", "Win32_"));
            }
            else
            {
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("===============================[ " + SystemCheckedWin32 + " ]===============================");
              lbSystemCheck->Items->Add("- Peripherique pas pris en Charge");
            }
          }
        }
      }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
           CoInitialize(NULL);
      if(CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0) != S_OK)
       {
         ShowMessage("Erreur d'initilization du Programme");
         Application->Terminate();
       }
       CoUninitialize();
     
     
     
     
     
     
         if(ClickSystemCheck == 0)
      {
        SystemCheck->Add("Win32_1394Controller");
        SystemCheck->Add("Win32_1394ControllerDevice");
        SystemCheck->Add("Win32_AllocatedResource");
        SystemCheck->Add("Win32_AssociatedBattery");
        SystemCheck->Add("Win32_AssociatedProcessor");
        SystemCheck->Add("Win32_AutochkSetting");
        SystemCheck->Add("Win32_BaseBoard");
        SystemCheck->Add("Win32_Battery");
        SystemCheck->Add("Win32_BIOS");
        SystemCheck->Add("Win32_Bus");
        SystemCheck->Add("Win32_CacheMemory");
        SystemCheck->Add("Win32_CDROMDrive");
        SystemCheck->Add("Win32_ControllerHasHub");
        SystemCheck->Add("Win32_CurrentProbe");
        SystemCheck->Add("Win32_DefragAnalysis");
        SystemCheck->Add("Win32_DesktopMonitor");
        SystemCheck->Add("Win32_DeviceBus");
        SystemCheck->Add("Win32_DeviceMemoryAdress");
        SystemCheck->Add("Win32_DeviceSettings");
        SystemCheck->Add("Win32_DiskDrive");
        SystemCheck->Add("Win32_DiskDrivePhysicalMedia");
        SystemCheck->Add("Win32_DisplayConfiguration");
        SystemCheck->Add("Win32_DisplayControllerConfiguration");
        SystemCheck->Add("Win32_DMAChannel");
        SystemCheck->Add("Win32_DriverForDevice");
        SystemCheck->Add("Win32_Fan");
        SystemCheck->Add("Win32_FloppyController");
        SystemCheck->Add("Win32_FloppyDrive");
        SystemCheck->Add("Win32_HeatPipe");
        SystemCheck->Add("Win32_IDEController");
        SystemCheck->Add("Win32_IDEControllerDevice");
        SystemCheck->Add("Win32_InfraredDevice");
        SystemCheck->Add("Win32_IRQRessource");
        SystemCheck->Add("Win32_Keyboard");
        SystemCheck->Add("Win32_MemoryArray");
        SystemCheck->Add("Win32_MemoryArrayLocation");
        SystemCheck->Add("Win32_MemoryDevice");
        SystemCheck->Add("Win32_MemoryDeviceArray");
        SystemCheck->Add("Win32_MemoryDeviceLocation");
        SystemCheck->Add("Win32_MotherboardDevice");
        SystemCheck->Add("Win32_MountPoint");
        SystemCheck->Add("Win32_NetworkAdapter");
        SystemCheck->Add("Win32_NetworkAdapterConfiguration");
        SystemCheck->Add("Win32_NetworkAdapterSetting");
        SystemCheck->Add("Win32_OnBoardDevice");
        SystemCheck->Add("Win32_ParallelPort");
        SystemCheck->Add("Win32_PCMCIAController");
        SystemCheck->Add("Win32_PhysicalMedia");
        SystemCheck->Add("Win32_PhysicalMemory");
        SystemCheck->Add("Win32_PhysicalMemoryArray");
        SystemCheck->Add("Win32_PhysicalMemoryLocation");
        SystemCheck->Add("Win32_PnPAllocatedResource");
        SystemCheck->Add("Win32_PnPDevice");
        SystemCheck->Add("Win32_PnPEntity");
        SystemCheck->Add("Win32_PnPSignedDriver");
        SystemCheck->Add("Win32_PnPSignedDriverCIMDataFile");
        SystemCheck->Add("Win32_PointingDevice");
        SystemCheck->Add("Win32_PortableBattery");
        SystemCheck->Add("Win32_PortConnector");
        SystemCheck->Add("Win32_PortRessource");
        SystemCheck->Add("Win32_PowerManagementEvent");
        SystemCheck->Add("Win32_POTSModem");
        SystemCheck->Add("Win32_POTSModemToSerialPort");
        SystemCheck->Add("Win32_Printer");
        SystemCheck->Add("Win32_PrinterConfiguration");
        SystemCheck->Add("Win32_PrinterController");
        SystemCheck->Add("Win32_PrinterDriver");
        SystemCheck->Add("Win32_PrinterDriverDll");
        SystemCheck->Add("Win32_PrinterSetting");
        SystemCheck->Add("Win32_PrintJob");
        SystemCheck->Add("Win32_Processor");
        SystemCheck->Add("Win32_Refrigeration");
        SystemCheck->Add("Win32_SCSIController");
        SystemCheck->Add("Win32_SCSIControllerDevice");
        SystemCheck->Add("Win32_SerialPort");
        SystemCheck->Add("Win32_SerialPortConfiguration");
        SystemCheck->Add("Win32_SerialPortSetting");
        SystemCheck->Add("Win32_SMBIOSMemory");
        SystemCheck->Add("Win32_SoundDevice");
        SystemCheck->Add("Win32_SystemBIOS");
        SystemCheck->Add("Win32_SystemDriverPnPEntity");
        SystemCheck->Add("Win32_SystemEnclosure");
        SystemCheck->Add("Win32_SystemMemoryResource");
        SystemCheck->Add("Win32_SystemSlot");
        SystemCheck->Add("Win32_TapeDrive");
        SystemCheck->Add("Win32_TCPIPPrinterPort");
        SystemCheck->Add("Win32_TemperatureProbe");
        SystemCheck->Add("Win32_UninterruptiblePowerSupply");
        SystemCheck->Add("Win32_USBController");
        SystemCheck->Add("Win32_USBControllerDevice");
        SystemCheck->Add("Win32_USBHub");
        SystemCheck->Add("Win32_VideoConfiguration");
        SystemCheck->Add("Win32_VideoController");
        SystemCheck->Add("Win32_VideoSettings");
        SystemCheck->Add("Win32_VoltageProbe");
     
        NbrSystemCheck = SystemCheck->Count;
     
        for(int NbrSystemCheckStrings = 0; NbrSystemCheckStrings<NbrSystemCheck; NbrSystemCheckStrings++)
        {
          AnsiString SystemCheckText = (SystemCheck->Strings[NbrSystemCheckStrings]);
          clbSystemCheck->Items->Add(AnsiReplaceText(SystemCheckText, "Win32_", " "));
        }
        ClickSystemCheck = 1;
      }
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
           CoInitialize(NULL);
      if(CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0) != S_OK)
       {
         ShowMessage("Erreur d'initilization du Programme");
         Application->Terminate();
       }
       CoUninitialize();  
        SystemCheck->Add("Win32_Processor");
        NbrSystemCheck = SystemCheck->Count;
     
     
        for(int NbrSystemCheckStrings = 0; NbrSystemCheckStrings<NbrSystemCheck; NbrSystemCheckStrings++)
        {
          AnsiString SystemCheckText = "Win32_Processor" ;
        }
     
            TStringList *SystemCheckViewLb = new TStringList();
            AnsiString SystemCheckedWin32 =  "Win32_Processor" ;
            GetWmiInfo(SystemCheckViewLb, AnsiReplaceText(SystemCheckedWin32, " ", "Win32_"));
            int NbrSystemCheckViewLb = SystemCheckViewLb->Count;
     
            if(NbrSystemCheckViewLb > 0)
            {
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("===============================[ " + SystemCheckedWin32 + " ]===============================");
              lbSystemCheck->Items->Add("");
              GetWmiInfo(lbSystemCheck->Items , AnsiReplaceText(SystemCheckedWin32, " ", "Win32_"));
            }
            else
            {
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("");
              lbSystemCheck->Items->Add("===============================[ " + SystemCheckedWin32 + " ]===============================");
              lbSystemCheck->Items->Add("- Peripherique pas pris en Charge");
            }
    }
     
    //---------------------------------------------------------------------------
    Et j ai egalement wbemuuid.lib

    Ce code est fonctionnel sur bcb6 de xp à seven

  15. #15
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut Blondelle
    Pour la FAQ j'ai transcrit un exemple écrit en delphi en c++ Builder
    le .h
    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
     
     
    #ifndef Unit45H
    #define Unit45H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include "WbemScripting_OCX.h"
    #include <OleServer.hpp>
    //---------------------------------------------------------------------------
    class TForm45 : public TForm
    {
    __published:	// Composants gérés par l'EDI
    	TMemo *Memo1;
    	TButton *Button1;
    	void __fastcall Button1Click(TObject *Sender);
    	void __fastcall FormDestroy(TObject *Sender);
    private:	// Déclarations utilisateur
         TSWbemLocator*    MLocator;
    public:		// Déclarations utilisateur
    	__fastcall TForm45(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm45 *Form45;
    //---------------------------------------------------------------------------
    #endif
    le source
    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
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
     
    //---------------------------------------------------------------------------
    #include <ComObj.hpp>
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit45.h"
     
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm45 *Form45;
    //---------------------------------------------------------------------------
    __fastcall TForm45::TForm45(TComponent* Owner)
    	: TForm(Owner)
    {
    	MLocator= new TSWbemLocator(this);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm45::Button1Click(TObject *Sender)
    {
      ISWbemServices* WmiService = NULL;
    	ISWbemObject* WmiObject = NULL;
    	ISWbemObjectSet* WmiObjectSet = NULL;
    	ISWbemProperty* WmiProperty = NULL;
    	ISWbemPropertySet* WmiPropertySet = NULL;
    	IEnumVARIANT* PropertyEnumerator = NULL;
    	IEnumVARIANT* ObjectEnumerator = NULL;
    	OleVariant ArrayVariant;
    	unsigned long NumberItem = 0;
    	TStringList* mProcessList;
     
    	try {
     
    		mProcessList = new TStringList();
    		mProcessList->Sorted=true;
    		WmiService = MLocator->ConnectServer(L".", L"ROOT\\CIMV2", NULL, NULL,
    			NULL, NULL, WbemConnectOptionsEnum::wbemConnectFlagUseMaxWait,
    			NULL);
    		WmiObjectSet = WmiService->ExecQuery(L"SELECT Name FROM Win32_Process",
    			L"WQL", WbemFlagEnum::wbemFlagReturnImmediately, NULL);
    		IEnumVARIANT* ObjectEnumerator = reinterpret_cast<IEnumVARIANT*>
    		(WmiObjectSet->_NewEnum);
    		while (ObjectEnumerator->Next(1, ArrayVariant, &NumberItem) == S_OK) {
    			WmiObject = reinterpret_cast<SWbemObject*>((IUnknown*)ArrayVariant);
    			OleCheck(WmiObject->get_Properties_(&WmiPropertySet));
    			PropertyEnumerator = (IEnumVARIANT*)WmiPropertySet->_NewEnum;
    			Variant tmp;
    			UnicodeString Handle;
    			while (PropertyEnumerator->Next(1, ArrayVariant,
    					&NumberItem) == S_OK) {
    				WmiProperty = reinterpret_cast<SWbemProperty*>
    				((IUnknown*)ArrayVariant);
    				UnicodeString Nom = WmiProperty->Name;
    				WmiProperty->get_Value(tmp);
    				if (Nom == L"Handle")
    					Handle.sprintf(L"%s%4.4d",L"Handle: ",StrToInt(tmp.bstrVal));
    				 else
    				   mProcessList->Add(Handle+(UnicodeString)L"  ProcessName:  "+tmp.bstrVal);
     
    			}
    			Memo1->Lines->Assign(mProcessList);
    			tmp = Unassigned;
    		}
    	}
    	__finally {
    		delete mProcessList;
    		WmiObjectSet->Release();
    		WmiService->Release();
     
    	}
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm45::FormDestroy(TObject *Sender)
    {
    	 delete MLocator;
    }
    //-------------------------------------------------------------------------
    la forme
    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
     
    object Form45: TForm45
      Left = 0
      Top = 0
      AutoSize = True
      Caption = 'Active Process with WMI API'
      ClientHeight = 581
      ClientWidth = 401
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      OnDestroy = FormDestroy
      PixelsPerInch = 96
      TextHeight = 13
      object Memo1: TMemo
        Left = 0
        Top = 0
        Width = 401
        Height = 529
        ScrollBars = ssVertical
        TabOrder = 0
      end
      object Button1: TButton
        Left = 0
        Top = 556
        Width = 113
        Height = 25
        Caption = 'GetActiveProcess'
        TabOrder = 1
        OnClick = Button1Click
      end
    end
    Cordialement
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  16. #16
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci DjmSoftware
    Merci cedni
    pour votre aide et vos exemples de code, je regarde en detail les exemples, vous avez deja repondu aux questions que j'allais poser, WMI est bien plus complexe que je ne le croyais (d'ou le nombre de question dans la Faq et Tutos Delphi)
    A+
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  17. #17
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci a tous pour votre aide
    Ce post est resolu voir ce lien
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

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

Discussions similaires

  1. Réponses: 12
    Dernier message: 26/03/2009, 17h29
  2. Réponses: 9
    Dernier message: 18/08/2008, 17h19
  3. Réponses: 5
    Dernier message: 11/04/2008, 12h53
  4. Réponses: 2
    Dernier message: 04/12/2007, 18h35
  5. Probleme lors de l'utilisation statspack
    Par magboom dans le forum Administration
    Réponses: 6
    Dernier message: 14/08/2007, 17h14

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