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

MFC Discussion :

Obtenir les taches en cours


Sujet :

MFC

  1. #1
    Candidat au Club
    Inscrit en
    Juin 2002
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1
    Points : 2
    Points
    2
    Par défaut Obtenir les taches en cours
    J'aimerai bien trouver la fonction qui ferait le systeme me renvoyer une liste des taches en cours, ainsi que leurs PID et des trucs comme ca ...

    merci

    mlerat22

  2. #2
    Bob
    Bob est déconnecté
    Membre averti
    Avatar de Bob
    Inscrit en
    Mars 2002
    Messages
    115
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 115
    Points : 378
    Points
    378
    Par défaut enumerer les processes
    CreateToolhelp32Snapshot()
    Process32First()
    Process32Next()
    Bob, Rédacteur C/C++ & PHP
    http://bob.developpez.com/

  3. #3
    fd
    fd est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut précision
    Les fnc de snapshot ne marchent que sur win9x.
    Sous nt ou 2000 il faut utiliser le registry

    un bout de code Microsoft
    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
     
    DWORD
    GetTaskListNT(
        PTASK_LIST  pTask,
        DWORD       dwNumTasks
        )
     
    /*++
     
    Routine Description:
     
        Provides an API for getting a list of tasks running at the time of the
        API call.  This function uses the registry performance data to get the
        task list and is therefore straight WIN32 calls that anyone can call.
     
    Arguments:
     
        dwNumTasks       - maximum number of tasks that the pTask array can hold
     
    Return Value:
     
        Number of tasks placed into the pTask array.
     
    --*/
     
    {
        DWORD                        rc;
        HKEY                         hKeyNames;
        DWORD                        dwType;
        DWORD                        dwSize;
        LPBYTE                       buf = NULL;
        CHAR                         szSubKey[1024];
        LANGID                       lid;
        LPSTR                        p;
        LPSTR                        p2;
        PPERF_DATA_BLOCK             pPerf;
        PPERF_OBJECT_TYPE            pObj;
        PPERF_INSTANCE_DEFINITION    pInst;
        PPERF_COUNTER_BLOCK          pCounter;
        PPERF_COUNTER_DEFINITION     pCounterDef;
        DWORD                        i;
        DWORD                        dwProcessIdTitle;
        DWORD                        dwProcessIdCounter;
        CHAR                         szProcessName[MAX_PATH];
        DWORD                        dwLimit = dwNumTasks - 1;
     
     
     
        //
        // Look for the list of counters.  Always use the neutral
        // English version, regardless of the local language.  We
        // are looking for some particular keys, and we are always
        // going to do our looking in English.  We are not going
        // to show the user the counter names, so there is no need
        // to go find the corresponding name in the local language.
        //
        lid = MAKELANGID( LANG_ENGLISH, SUBLANG_NEUTRAL );
        sprintf( szSubKey, "%s\\%03x", REGKEY_PERF, lid );
        rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                           szSubKey,
                           0,
                           KEY_READ,
                           &hKeyNames
                         );
        if (rc != ERROR_SUCCESS) {
            goto exit;
        }
     
        //
        // get the buffer size for the counter names
        //
        rc = RegQueryValueEx( hKeyNames,
                              REGSUBKEY_COUNTERS,
                              NULL,
                              &dwType,
                              NULL,
                              &dwSize
                            );
     
        if (rc != ERROR_SUCCESS) {
            goto exit;
        }
     
        //
        // allocate the counter names buffer
        //
        buf = (LPBYTE) malloc( dwSize );
        if (buf == NULL) {
            goto exit;
        }
        memset( buf, 0, dwSize );
     
        //
        // read the counter names from the registry
        //
        rc = RegQueryValueEx( hKeyNames,
                              REGSUBKEY_COUNTERS,
                              NULL,
                              &dwType,
                              buf,
                              &dwSize
                            );
     
        if (rc != ERROR_SUCCESS) {
            goto exit;
        }
     
        //
        // now loop thru the counter names looking for the following counters:
        //
        //      1.  "Process"           process name
        //      2.  "ID Process"        process id
        //
        // the buffer contains multiple null terminated strings and then
        // finally null terminated at the end.  the strings are in pairs of
        // counter number and counter name.
        //
     
        p = buf;
        while (*p) {
            if (p > buf) {
                for( p2=p-2; isdigit(*p2); p2--) ;
                }
            if (stricmp(p, PROCESS_COUNTER) == 0) {
                //
                // look backwards for the counter number
                //
                for( p2=p-2; isdigit(*p2); p2--) ;
                strcpy( szSubKey, p2+1 );
            }
            else
            if (stricmp(p, PROCESSID_COUNTER) == 0) {
                //
                // look backwards for the counter number
                //
                for( p2=p-2; isdigit(*p2); p2--) ;
                dwProcessIdTitle = atol( p2+1 );
            }
            //
            // next string
            //
            p += (strlen(p) + 1);
        }
     
        //
        // free the counter names buffer
        //
        free( buf );
     
     
        //
        // allocate the initial buffer for the performance data
        //
        dwSize = INITIAL_SIZE;
        buf = malloc( dwSize );
        if (buf == NULL) {
            goto exit;
        }
        memset( buf, 0, dwSize );
     
     
        while (TRUE) {
     
            rc = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
                                  szSubKey,
                                  NULL,
                                  &dwType,
                                  buf,
                                  &dwSize
                                );
     
            pPerf = (PPERF_DATA_BLOCK) buf;
     
            //
            // check for success and valid perf data block signature
            //
            if ((rc == ERROR_SUCCESS) &&
                (dwSize > 0) &&
                (pPerf)->Signature[0] == (WCHAR)'P' &&
                (pPerf)->Signature[1] == (WCHAR)'E' &&
                (pPerf)->Signature[2] == (WCHAR)'R' &&
                (pPerf)->Signature[3] == (WCHAR)'F' ) {
                break;
            }
     
            //
            // if buffer is not big enough, reallocate and try again
            //
            if (rc == ERROR_MORE_DATA) {
                dwSize += EXTEND_SIZE;
                buf = realloc( buf, dwSize );
                memset( buf, 0, dwSize );
            }
            else {
                goto exit;
            }
        }
     
        //
        // set the perf_object_type pointer
        //
        pObj = (PPERF_OBJECT_TYPE) ((DWORD)pPerf + pPerf->HeaderLength);
     
        //
        // loop thru the performance counter definition records looking
        // for the process id counter and then save its offset
        //
        pCounterDef = (PPERF_COUNTER_DEFINITION) ((DWORD)pObj + pObj->HeaderLength);
        for (i=0; i<(DWORD)pObj->NumCounters; i++) {
            if (pCounterDef->CounterNameTitleIndex == dwProcessIdTitle) {
                dwProcessIdCounter = pCounterDef->CounterOffset;
                break;
            }
            pCounterDef++;
        }
     
        dwNumTasks = min( dwLimit, (DWORD)pObj->NumInstances );
     
        pInst = (PPERF_INSTANCE_DEFINITION) ((DWORD)pObj + pObj->DefinitionLength);
     
        //
        // loop thru the performance instance data extracting each process name
        // and process id
        //
        for (i=0; i<dwNumTasks; i++) {
            //
            // pointer to the process name
            //
            p = (LPSTR) ((DWORD)pInst + pInst->NameOffset);
     
            //
            // convert it to ascii
            //
            rc = WideCharToMultiByte( CP_ACP,
                                      0,
                                      (LPCWSTR)p,
                                      -1,
                                      szProcessName,
                                      sizeof(szProcessName),
                                      NULL,
                                      NULL
                                    );
     
            if (!rc) {
                //
    	    // if we cant convert the string then use a default value
                //
                strcpy( pTask->ProcessName, UNKNOWN_TASK );
            }
     
            if (strlen(szProcessName)+4 <= sizeof(pTask->ProcessName)) {
                strcpy( pTask->ProcessName, szProcessName );
                strcat( pTask->ProcessName, ".exe" );
            }
     
            //
            // get the process id
            //
            pCounter = (PPERF_COUNTER_BLOCK) ((DWORD)pInst + pInst->ByteLength);
            pTask->flags = 0;
            pTask->dwProcessId = *((LPDWORD) ((DWORD)pCounter + dwProcessIdCounter));
            if (pTask->dwProcessId == 0) {
                pTask->dwProcessId = (DWORD)-2;
            }
     
            //
            // next process
            //
            pTask++;
            pInst = (PPERF_INSTANCE_DEFINITION) ((DWORD)pCounter + pCounter->ByteLength);
        }
     
    exit:
        if (buf) {
            free( buf );
        }
     
        RegCloseKey( hKeyNames );
        RegCloseKey( HKEY_PERFORMANCE_DATA );
     
        return dwNumTasks;
    }

  4. #4
    Bob
    Bob est déconnecté
    Membre averti
    Avatar de Bob
    Inscrit en
    Mars 2002
    Messages
    115
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 115
    Points : 378
    Points
    378
    Par défaut reponse de fd
    Stp, fd utilise les balises BBcode.
    Si tu fais
    c'est beaucoup plus lisible.
    Bob, Rédacteur C/C++ & PHP
    http://bob.developpez.com/

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

Discussions similaires

  1. [crontab] Obtenir les prochaines taches qui seront exécutées
    Par mrjay42 dans le forum Administration système
    Réponses: 3
    Dernier message: 14/10/2009, 13h24
  2. Comment obtenir les cours de la bourse ?
    Par maximenet dans le forum Débuter
    Réponses: 5
    Dernier message: 20/12/2007, 16h37
  3. Stats : connaitre en temps reel les requetes en cours d'exec
    Par jeff37 dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 21/12/2004, 17h01
  4. [Débutant][VB 5.0] Obtenir les groupes locaux W2K
    Par Banana_Ultra dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 01/10/2004, 14h07
  5. [VBA]Obtenir les noms des polices disponibles
    Par xp dans le forum VBA Access
    Réponses: 2
    Dernier message: 04/03/2004, 15h39

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