1

RunAs のように動作するプログラムを作成しました。正常に動作しますが、1 つ問題があります。たとえば、compmgmt.msc を実行する場合は、mmc.exe と compmgmt.msc をパラメーターとして実行する必要があります。コンピューターの管理は開きますが、実行したいのでユーザーの下ではありません。ログインしているそのユーザー名で実行されます。その理由を誰か教えてもらえますか?どうすれば修正できますか? これが私のコードです:

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

ご協力いただきありがとうございます!

カンピ

4

1 に答える 1

1

オンラインのMSDNドキュメントを見たことがありますか?

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

サンプルコードをご覧ください。かなり簡単なようです。

于 2009-09-28T16:41:58.947 に答える