PC Review


Reply
Thread Tools Rate Thread

CreateProcessAsUserW always returns ERROR_INVALID_PARAMETER

 
 
user1976
Guest
Posts: n/a
 
      29th Nov 2004
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;
}
 
Reply With Quote
 
 
 
 
Steve Friedl [MVP/Security]
Guest
Posts: n/a
 
      29th Nov 2004
"user1976" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

--
Steve Friedl -- Tustin, California USA -- www.unixwiz.net
Unix Wizard -- Microsoft MVP/Security -- I speak for me only


 
Reply With Quote
 
Bill_Hao
Guest
Posts: n/a
 
      12th Aug 2005
Hi, Steve,
I met the same problem again.
Would you mind give me more clear explaination?

Bill

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO recordset returns no records, identical SQL string returns when pasted in query todd.tharp@gmail.com Microsoft Access 19 5th Aug 2011 06:53 AM
Re: Vlookup returns #N/A when Range is 'false', but returns valueswhen 'true' Pete_UK Microsoft Excel Worksheet Functions 1 8th Mar 2010 02:36 PM
Index with mulitple value returns and muliple column returns solar+CSE Microsoft Excel Worksheet Functions 4 12th Jun 2009 04:43 PM
Impersonation / CreateProcessAsUserW Permissions Steven Microsoft ASP .NET 0 22nd Apr 2008 03:13 PM
Recordset only returns first record, when Query SQL returns 51 records Alex Microsoft Access VBA Modules 1 16th Jul 2003 01:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.