Вот этот код решает такую задачу:
//get Active UI session
ulSessionId = WTSGetActiveConsoleSessionId();
WTSQueryUserToken (ulSessionId, &hTokenthis);
DuplicateTokenEx(hTokenthis, TOKEN_ALL_ACCESS|TOKEN_EXECUTE,
        NULL, SecurityIdentification, TokenPrimary, &hToken);
// Start the child process.
if ( CreateEnvironmentBlock(&lpEnvironment, hToken, TRUE) ) 
{
    char * path = "C:\\program.exe --run";
    // Start the child process. 
    if( !CreateProcessAsUser( hToken,
        NULL, 
        path,           // Command line
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        NORMAL_PRIORITY_CLASS |CREATE_UNICODE_ENVIRONMENT,
        lpEnvironment,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi)           // Pointer to PROCESS_INFORMATION structure
        ) 
    {
        OutputDebugString( "CreateProcess failed" );
    }
}
Комментариев нет:
Отправить комментарий