2009-09-28 2 views
1

J'ai écrit un programme qui devrait fonctionner comme RunAs. Cela fonctionne très bien, mais j'ai un problème avec ça. Si je veux exécuter par exemple compmgmt.msc, alors je devrais lancer mmc.exe et compmgmt.msc comme paramètre. Gestion de l'ordinateur s'ouvre, mais pas sous l'utilisateur que je veux l'exécuter. Il fonctionnera sous ce nom d'utilisateur qui est connecté. Quelqu'un peut-il me dire pourquoi, et comment puis-je le corriger? Voici mon code:CreateProcessWithLogonW et mmc.exe

void createproc(
     wchar_t * user, 
     wchar_t * domain, 
     wchar_t * pass, 
     wchar_t * applicationname) 
{ 
    int errorcode; 
    char cmd[Buf_Size]; 

    STARTUPINFO StartInfo; 
    PROCESS_INFORMATION ProcInfo; 
    memset(&ProcInfo, 0, sizeof(ProcInfo)); 
    memset(&StartInfo, 0 , sizeof(StartInfo)); 
    StartInfo.cb = sizeof(StartInfo); 
    StartInfo.wShowWindow = SW_HIDE; 

    int bFuncRetn = 
    CreateProcessWithLogonW 
    (
     user, 
     domain, 
     pass, 
     LOGON_NETCREDENTIALS_ONLY, 
     L"C:\\Windows\\System32\\mmc.exe", //applicationname, 
     L" compmgmt.msc", 
     CREATE_UNICODE_ENVIRONMENT, 
     NULL, 
     NULL, 
     (LPSTARTUPINFOW)&StartInfo, 
     &ProcInfo 
    ); 

    errorcode = GetLastError(); 

    if (bFuncRetn == 0) 
    { 
     CloseHandle(ProcInfo.hProcess); 
     CloseHandle(ProcInfo.hThread); 
     printf("\nGetLastError :: %d CreateProcessWithLogonW Failed!", 
      errorcode); 
     printf("\nFor more information type :: Net Helpmsg %d", 
      errorcode); 
     getch(); 
     exit(1); 
    } 

    CloseHandle(ProcInfo.hProcess); 
    CloseHandle(ProcInfo.hThread); 

}//createproc 

Merci pour votre aide!

Kampi

Répondre

1

Avez-vous regardé la documentation MSDN en ligne?

http://msdn.microsoft.com/en-us/library/ms682431(VS.85).aspx

Jetez un oeil à l'exemple de code. Cela semble assez simple.

+0

Salut! Tu as raison! Cela m'a beaucoup aidé. Je l'ai trouvé plus tôt, mais je n'étais pas si prudent. Si j'utilise LOGON_WITH_PROFILE au lieu de LOGON_NETCREDENTIALS_ONLY cela fonctionne très bien! Merci pour votre aide! Kampi – kampi

Questions connexes