Bonjour,

Je veux executer une application en mode administrateur a partir d'une autre application. J'utilise le code suivant:
J'ai mis comme seconde application (calc.exe) pour les tests.
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
 
__fastcall TFrm_Main::TFrm_Main(TComponent* Owner)
    : TForm(Owner)
{
    bool bResult = this->RunAsAdmin(this->Handle, GetCurrentDir(), "calc.exe", "");
    if (!bResult) {
        MessageDlg("An internal error has occured !", mtError, TMsgDlgButtons() << mbOK, 0);
    }
    Application->Terminate();
}
//---------------------------------------------------------------------------
bool __fastcall TFrm_Main::RunAsAdmin(HWND hwnd, AnsiString aPath, AnsiString aFile, AnsiString aParams)
{
    SHELLEXECUTEINFO Sei;
 
    memset(&Sei, 0, sizeof(Sei));
    Sei.cbSize = sizeof(Sei);
    Sei.hwnd = hwnd;
    Sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI;
    Sei.lpFile = aFile.c_str();
    Sei.lpDirectory = aPath.c_str();
    Sei.lpVerb = "runas";
    Sei.lpParameters = aParams.c_str();
    Sei.nShow = SW_SHOWNORMAL;
 
 
    bool res = ShellExecuteEx(&Sei);
    return(res);
}
//---------------------------------------------------------------------------
Ce code fonctionne bien avec Windows XP, au lancement j'ai bien une fenetre "Run As" pour demander a l'ustilisateur d'executer cette application en tant qu'administrateur.
Mais sous windows 7, cette fenetre n'apparait pas, et l'application est executee sans mode administrateur.

Est-ce que j'ai mal fait quelque chose, ou alors c'est a cause de windows 7 ?

Merci
Fred