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++ Discussion :

ClearEventLog par WBEM


Sujet :

C++

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 35
    Points : 27
    Points
    27
    Par défaut ClearEventLog par WBEM
    Bonjour,

    J'aimerai faire la même chose que ce script en Studio 2005 C++ :

    --------------------------------------------------------------
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    strComputer = InputBox("Entrer le nom ou l'ip de la machine")
     
    if strComputer <> "" then	
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
      Set colLogFiles = objWMIService.ExecQuery ("Select * from Win32_NTEventLogFile where LogFileName='System'")	
     
      For Each objLogfile in colLogFiles 
        objLogFile.ClearEventLog() 
      Next
     End if
    --------------------------------------------------------------

    Mais je rencontre un problème avec "ExecMethod" et "ClearEventLog".
    Est ce que quelqu'un pourrait me donner un exemple de code ou des conseils ?
    Merci d'avance.

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 35
    Points : 27
    Points
    27
    Par défaut
    J'ai trouvé ce code sur le net. Si je n'ai plus les erreurs sur "ExecMethod" et "ClearEventLog", les logs ne sont pas effacés :

    Si vous avez une idée ...

    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
     
    #include "stdafx.h"
     
    #include <iostream>
    #define _WIN32_DCOM 
     
    using namespace std ; 
     
    #include <windows.h> 
    #include <comdef.h> 
    #include <wbemcli.h> 
     
    #pragma comment(lib, "Wbemuuid") 
     
    int main(int argc,char**argv) 
    { 
      IWbemLocator *pLocator = NULL; 
      IWbemServices *pNamespace = 0; 
      IWbemClassObject * pClass = NULL; 
    //    IWbemClassObject * pOutInst = NULL; 
      IWbemClassObject * pInClass = NULL; 
      IWbemClassObject * pInInst = NULL; 
     
      IWbemCallResult *pCallRes = NULL; 
      IWbemClassObject *pObj = NULL; 
     
      BSTR path = SysAllocString(L"\\\\.\\ROOT\\CIMV2"); 
      BSTR ClassPath = SysAllocString(L"Win32_NTEventlogFile"); 
      BSTR MethodName = SysAllocString(L"ClearEventLog"); 
      BSTR ArgName = SysAllocString(L"ArchiveFileName"); 
     
      // Initialize COM and connect to WMI. 
      HRESULT hr = CoInitialize(0); 
      hr = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator,(LPVOID *) &pLocator); 
      if SUCCEEDED(hr) 
      { 
        printf("WbemLocator OK!\n"); 
      } 
     
      hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL, &pNamespace); 
      if SUCCEEDED(hr) 
      { 
        printf("ConnectServer OK!\n"); 
      } 
      else 
      { 
        IErrorInfo *pIErrorInfo; 
        GetErrorInfo(0,&pIErrorInfo); 
        BSTR desc; 
        pIErrorInfo->GetDescription(&desc); 
      } 
     
      // Get the class object for the method definition. 
      hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL); 
      if SUCCEEDED(hr) 
      { 
        printf("GetObject OK!\n"); 
      } 
      else 
      { 
        IErrorInfo *pIErrorInfo; 
        GetErrorInfo(0,&pIErrorInfo); 
        BSTR desc; 
        pIErrorInfo->GetDescription(&desc); 
      } 
     
      // Get the input-argument class object and create an instance. 
      hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL); 
      if SUCCEEDED(hr) 
      { 
        printf("GetMethod OK!\n"); 
      } 
      else 
      {  
        IErrorInfo *pIErrorInfo; 
        GetErrorInfo(0,&pIErrorInfo); 
        BSTR desc; 
        pIErrorInfo->GetDescription(&desc); 
      } 
     
      hr = pInClass->SpawnInstance(0, &pInInst); 
      if SUCCEEDED(hr) 
      { 
        printf("SpawnInstance OK!\n"); 
      } 
      else 
      { 
        IErrorInfo *pIErrorInfo; 
        GetErrorInfo(0,&pIErrorInfo); 
        BSTR desc; 
        pIErrorInfo->GetDescription(&desc); 
      } 
     
      // Set the property. 
    // BSTR Filename=L"C:\WINDOWS\system32\config\OSession.evt"; 
      VARIANT var; 
      var.vt = VT_BSTR; 
      //var.bstrVal= SysAllocString(L"C:\\WINNT\\system32\\config\\AppEvent.Evt"); 
      var.bstrVal= SysAllocString(L"C:\\WINNT\\system32\\config\\SysEvent.Evt"); 
      //var.bstrVal= SysAllocString(L"C:\\WINNT\\system32\\config\\SecEvent.Evt"); 
      hr = pInInst->Put(ArgName, 0, &var, 0); 
      if SUCCEEDED(hr) 
      { 
        printf("Put OK!\n"); 
      } 
      else 
      { 
        IErrorInfo *pIErrorInfo; 
        GetErrorInfo(0,&pIErrorInfo); 
        BSTR desc; 
        pIErrorInfo->GetDescription(&desc); 
      } 
     
      VariantClear(&var); 
     
      // Call the method. 
    //    hr = pNamespace->ExecMethod(ClassPath, MethodName, 0, NULL, pInInst, &pOutInst, NULL); 
    //    hr = pNamespace->ExecMethod(ClassPath,MethodName,NULL,NULL,pInInst,NULL,&pCallRes); 
      hr = pNamespace->ExecMethod(ClassPath,MethodName,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,pInInst,NULL,&pCallRes); 
      if (WBEM_S_NO_ERROR==hr) 
      { 
        printf("ExecMethod OK!\n"); 
      } 
      else 
      {  
        IErrorInfo *pIErrorInfo; 
        GetErrorInfo(0,&pIErrorInfo); 
        BSTR desc; 
        pIErrorInfo->GetDescription(&desc); 
      } 
     
      while (true) 
      { 
        LONG lStatus = 0; 
        HRESULT hRes = pCallRes->GetCallStatus(0, &lStatus); 
        if ((hRes == WBEM_S_NO_ERROR)) 
             break; 
     
        if ((hRes == WBEM_S_TIMEDOUT)) 
            continue; 
      } 
     
      hr = pCallRes->GetResultObject(WBEM_INFINITE, &pObj); 
     
    /*    if (hr) 
        { 
            pCallRes->Release(); 
            return 1; 
        } 
    */ 
    /*    VARIANT varReturnValue; 
    VariantInit(&varReturnValue); 
        hr = pObj->Get(_bstr_t(L"ReturnValue"),0,&varReturnValue,NULL,0); 
    //    hr = pObj->Get(L"ReturnValue",0,&varReturnValue,NULL,0); 
     
        cout < < varReturnValue.lVal < < endl; 
    */ 
      IErrorInfo *pIErrorInfo; 
      GetErrorInfo(0,&pIErrorInfo); 
      BSTR desc; 
      pIErrorInfo->GetDescription(&desc); 
     
      // property "ReturnValue" and the returned string is in the 
      // property "sOutArg". 
      //hr = pOutInst->GetObjectText(0, &Text); 
      //printf("\nThe object text is:\n%S", Text); 
     
      // Free up resources. 
      SysFreeString(path); 
      SysFreeString(ClassPath); 
      SysFreeString(MethodName); 
      SysFreeString(ArgName); 
      pCallRes->Release(); 
      pClass->Release(); 
      pInInst->Release(); 
      pInClass->Release(); 
      //pOutInst->Release(); 
      pLocator->Release(); 
      pNamespace->Release(); 
      CoUninitialize(); 
      printf("Terminating normally\n"); 
     
      return 0; 
      // Program successfully completed. 
    }

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 35
    Points : 27
    Points
    27
    Par défaut
    Pas d'idées ?

Discussions similaires

  1. Réponses: 29
    Dernier message: 14/01/2013, 10h40
  2. tutoriel : La programmation de l'API Windows en C++ par Bob
    Par Aurelien.Regat-Barrel dans le forum Windows
    Réponses: 19
    Dernier message: 21/06/2008, 14h34
  3. [TImage] Transfert de Picture par pixels.
    Par H2D dans le forum Langage
    Réponses: 9
    Dernier message: 25/10/2003, 14h37
  4. Affichage en passant par un buffer...
    Par Sirotilc dans le forum MFC
    Réponses: 5
    Dernier message: 27/05/2002, 21h00

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