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
   |  
bool Serveur::GetUserProcess(DWORD dwIDProc, WCHAR*szName)
{
    // Recuperation du nom de l'utilisateur utilisant le process
    HANDLE haProcess;
    PSECURITY_DESCRIPTOR psdRecup;
    SID_NAME_USE snuName;
    BOOL boOwner;
    DWORD dwSize;
    PSID psid;
    wchar_t * szDomain;
    DWORD dwNameSize = 64;
    DWORD dwSizeDom = 64;
    szDomain = (wchar_t*)GlobalAlloc(GMEM_FIXED,51);
    psdRecup = (PSECURITY_DESCRIPTOR)GlobalAlloc(GMEM_FIXED,1000);
    /*
    * Récupère le handle du processus , pour lire la sécurité du fichier .
    * READ_CONTROL doit être présent dans le handle du processus.
    */
    haProcess = OpenProcess(READ_CONTROL,TRUE,dwIDProc);
    if (haProcess == NULL) { return FALSE;}
    if ((GetKernelObjectSecurity(haProcess,OWNER_SECURITY_INFORMATION,psdRecup,1000,&dwSize)) == 0 ) {CloseHandle(haProcess); return FALSE;}
    if ((GetSecurityDescriptorOwner(psdRecup,&psid, &boOwner)) == 0) {CloseHandle(haProcess); return FALSE;}
    if ((LookupAccountSid(NULL,psid,szName,&dwNameSize,szDomain,&dwSizeDom,&snuName)) == 0) {CloseHandle(haProcess); return FALSE;}
    etatServeur->setText(etatServeur->toPlainText()+"\r\n snuName : " + QString::number(snuName));
    char *Domain = new char[4096];
    wcstombs(Domain, szDomain, 64);
    etatServeur->setText(etatServeur->toPlainText()+"\r\n szDomain : " + Domain + " PID dflksdfhj : " + QString::number(dwIDProc));
    GlobalFree(psdRecup);
    GlobalFree(szDomain);
    return TRUE;
}
 
bool Serveur::GetProcessList()
{
    // Recuperation de la liste des processus en cours
    HANDLE hProcessSnap;
    HANDLE hProcess;
    PROCESSENTRY32 pe32;
    DWORD dwPriorityClass;
    DWORD dwSizeCurUSer = 30;
    WCHAR szUserProcess[30+1];
    WCHAR szCurUser[30+1];
    GetUserName(szCurUser,&dwSizeCurUSer);
    // Take a snapshot of all processes in the system.
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 1);
    // Set the size of the structure before using it.
    pe32.dwSize = sizeof(PROCESSENTRY32);
    // Retrieve information about the first process,
    // and exit if unsuccessful
    if (!Process32First(hProcessSnap, &pe32)) {
        CloseHandle(hProcessSnap);          // clean the snapshot object
        return false;
    }
    // Now walk the snapshot of processes, and
    // display information about each process in turn
    do {
        GetUserProcess(pe32.th32ProcessID, szUserProcess);
        char *UserProcess = new char[4096];
        wcstombs(UserProcess, szUserProcess, 64);
        QString text(UserProcess);
       // if (NumeroProcess == pe32.th32ProcessID)
            etatServeur->setText(etatServeur->toPlainText()+"\r\n personne : " + text + " PID : " + QString::number(pe32.th32ProcessID));
 
        if (!ListClientProcess.contains(text))
            ListClientProcess.append(text);
        // Retrieve the priority class.
        dwPriorityClass = 0;
        hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
        if (hProcess != NULL) {
            dwPriorityClass = GetPriorityClass(hProcess);
            if (!dwPriorityClass)
                qDebug() << "GetPriorityClass";
            CloseHandle(hProcess);
        }
    } while (Process32Next(hProcessSnap, &pe32));
    CloseHandle(hProcessSnap);
    return true;
} | 
Partager