tags:

views:

189

answers:

1

Hi!

I wrote a program, that should work like RunAs. It works fine, but i have one problem with it. If i want to run for example compmgmt.msc, then i should run mmc.exe and compmgmt.msc as it's parameter. Computer Management will open, but not under the user as i want to run it. It will run under that username who is logged in. Can someone tell me why is that, and how can i correct it? Here is my code :

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

Thanks for your help!

kampi

A: 

Have you looked at the online MSDN docs?

http://msdn.microsoft.com/en-us/library/ms682431%28VS.85%29.aspx

Have a look at the sample code. Seems pretty straightforward.

Bukes
Hi! You're right! This helped me a lot. I found it earlier too, but i wasn't so careful. If i use LOGON_WITH_PROFILE instead of LOGON_NETCREDENTIALS_ONLY it works fine!Thanks for your help!kampi
kampi