Bonjour,

j'aimerais pouvoir créer un processus avec les privilèges administrateurs - ici Install - (jeton complet) à partir d'un processus avec des droits utilisateurs - ici MainProcess - qui attendrait la fin de celui-ci avant de continuer.

Cela passe evidemment par une élévation de jeton (donc pas possible avec CreateProcess).

J'ai déjà lu ça. Mais mon programme ne fonctionne pas.

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
// MainProcess  [...]
        CString strInstall= str + "\\Install.exe";
 
        SHELLEXECUTEINFO ShellExInfo; 
        ZeroMemory(&ShellExInfo, sizeof(SHELLEXECUTEINFO)); 
        ShellExInfo.cbSize = sizeof( SHELLEXECUTEINFO ); 
 
        ShellExInfo.lpFile = strInstall; 
        ShellExInfo.fMask  = SEE_MASK_NOCLOSEPROCESS; 
        ShellExInfo.lpVerb = _T("open");
        ShellExInfo.nShow  = SW_SHOW ; 
 
        CString strOut = "ShellExecuteEx "+strInstall;
        OutputDebugString(strOut);
        if(ShellExecuteEx(&ShellExInfo)) 
        { 
            OutputDebugString("ShellExecuteEx reussi");
            WaitForSingleObject(ShellExInfo.hProcess, INFINITE);
            CloseHandle(ShellExInfo.hProcess);
        }
        else
        {
            OutputDebugString("ShellExecuteEx echec");
            CloseHandle(ShellExInfo.hProcess); 
            return FALSE;
        }
        /*
        if( ShellExecute(NULL,"open",strInstall,"","",SW_NORMAL ) )
        {
            OutputDebugString("ShellExecute succes ");
        }
        else
        {
            OutputDebugString("ShellExecute echec ");
        }*/
//[...]
résultat (Vista) :
pas de demande d'élévation, un process Install zombie (pas d'affichage, persitance dans liste des processus), le process MainProcess continue (aucune attente)

en remplaçant ShellExInfo.lpVerb = _T("open"); par ShellExInfo.lpVerb = _T("runas");
une demande d'élévation, pas de process Install, le process MainProcess continue

en décommentant la partie ShellExecute
deux demandes d'élévation, deux process Install, le process MainProcess continue

en décommentant la partie ShellExecute et en remplaçant ShellExInfo.lpVerb = _T("open"); par ShellExInfo.lpVerb = _T("runas");
deux demandes d'élévation, deux process Install, le process MainProcess continue

Il pourrait s'agir d'un problème de droits (un processus utilisiateur ne pouvant "commander" avec un processus administrateur), mais je veux juste attendre sa terminaison ...

Si quelqu'un à une idée (merci d'avance).

PS : Vista promet déjà de folles heures d'amusement