CreateProcessAsUserW always returns ERROR_INVALID_PARAMETER

U

user1976

Hi all, I have the following function that I execute from a service
running on
win2003 terminal server. This code creates a process in a client's
terminal session. I got this to work on win 2000 server. But when I
run in 2003 I always
keep getting ERROR_INVALID_PARAMETER from the function
CreateProcessAsUserW .
I verified the code and every thing seems right. I am trying to create
some thing as simple as c:\w2k3\notepad.exe and it still gives this
error. Any body with ideas please help me out

int createTSProcess(char* userName,char* domain,char* passwd,char*
commandStr,char* processDir,long sessionId){
HANDLE hToken;
PROCESS_INFORMATION pi;
STARTUPINFOW si;
LPVOID lpEnvironment = NULL;

// initialize STARTUPINFO structure
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
__try {
// obtain an access token for the given user
if (!LogonUser(userName,domain,passwd,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,&hToken))
{
showError("LogonUser:");
return FAILURE_AUTH_FAILURE;
}

if(EnableSecurityRights(SE_TCB_NAME, TRUE) != ERROR_SUCCESS) {
showError("EnableSecurityRights:");
return FAILURE_SETTOKEN_FAILURE;
}
//cout<<"Successfully enabled priveleges\n";

DWORD dwSessionId = sessionId;
if(!SetTokenInformation(hToken, TokenSessionId, &dwSessionId,
sizeof(DWORD))) {
showError("SetTokenInformation:");
return FAILURE_SETTOKEN_FAILURE;
}
//cout<<"Successfully set token\n";
// Unicode usage due to CreateProcessAsUserA bug (Q257193)
wchar_t wszCommand[4096];
if(!MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, commandStr, -1,
wszCommand, 4096)) {
showError("MultiByteToWideChar:");
return FAILURE_CREATEPROCESS_FAILURE;
} else {
if( !CreateProcessAsUserW(
hToken, // client's access token
NULL, // file to execute
wszCommand, // command line
NULL, // pointer to process SECURITY_ATTRIBUTES
NULL, // pointer to thread SECURITY_ATTRIBUTES
TRUE, // handles are not inheritable
NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, // creation
flags
NULL, // pointer to new environment block
NULL, // name of current directory
&si, // pointer to STARTUPINFO structure
&pi) // receives information about new process
) {
showError("CreateProcessAsUserW:");
cout<<"Create process failed\n";
return FAILURE_CREATEPROCESS_FAILURE;
}
}
}
__finally {
// Close the opened handles.
if (hToken) CloseHandle(hToken);
if (pi.hProcess) CloseHandle(pi.hProcess);
if (pi.hThread) CloseHandle(pi.hThread);
if (lpEnvironment != NULL) DestroyEnvironmentBlock(lpEnvironment);
}
return pi.dwProcessId;
}
 
S

Steve Friedl [MVP/Security]

user1976 said:
if( !CreateProcessAsUserW(
...
NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT,
NULL, // pointer to new environment block
...

I notice that CREATE_UNICODE_ENVIRONMENT is specified, but there is no
environment block: is it possible that this could be causing the confusion?

(and yes, this is a stretch)

Steve
 
B

Bill_Hao

Hi, Steve,
I met the same problem again.
Would you mind give me more clear explaination?

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top