Click to See Complete Forum and Search --> : service and CreateProcessAsUser


preetham
July 23rd, 2003, 11:39 AM
Hi All,
I have written a service that would execute an under the admin login. However, i would like to display it
on my desktop.
Below is the code:
LPTSTR lpszUsername = "administrator";
LPTSTR lpszDomain = "xxxxx";
LPTSTR lpszPassword = "xxxxx";
HANDLE hUser;

BOOL bULogon = LogonUser( lpszUsername, // string that specifies the user name
lpszDomain, // string that specifies the domain or server
lpszPassword, // string that specifies the password
LOGON32_LOGON_BATCH, // specifies the type of logon operation
LOGON32_PROVIDER_DEFAULT , // specifies the logon provider
&hUser); // pointer to variable to receive token handle
if(!bULogon)
{
DebugMessage("ERROR:Falied to logon");
}

STARTUPINFO startupInfo;
PROCESS_INFORMATION processInformation;

memset(&startupInfo, 0, sizeof(startupInfo));
memset(&processInformation, 0, sizeof(processInformation));
startupInfo.lpDesktop = _T("winsta0\\default");


BOOL bProc = CreateProcessAsUser(hUser, // handle to a token that represents a logged-on user
NULL, // pointer to name of executable module
"C:\\windows\\notepad.exe",
NULL, // pointer to process security attributes
NULL, // pointer to thread security attributes
FALSE, // new process inherits handles
CREATE_NEW_CONSOLE, // creation flags
NULL, // pointer to new environment block
NULL, // pointer to current directory name
&startupInfo, // pointer to STARTUPINFO
&processInformation); // pointer to PROCESS_INFORMATION
if(!bProc)
{
DebugMessage("ERROR: Falied Creating process as user");
}
// Wait until application has terminated
WaitForSingleObject(processInformation.hProcess, INFINITE);

When i start the service, the above code executes. It opens notepad in the administrators account while displaying
it on my desktop. However, the notepad window i see on my screen i not painted clearly. All i see is the titlebar and
the outer frame. Why is the problem.
Is there any way i can execute an application under the administrator and display it in my login desktop.
Appreciate the help.
Thank you,
Preetham.

rxbagain
July 24th, 2003, 02:57 AM
Try to change LOGON32_LOGON_BATCH with LOGON32_LOGON_INTERACTIVE. I did not tried your code because using LOGON32_LOGON_BATCH generates error in my system. Testing it though with LOGON32_LOGON_INTERACTIVE works well.

Hope it will help you

KimSiah Ng
September 24th, 2003, 07:34 AM
I use the code shown and found that it can open the notepad but not the wordpad (c:\winnt\system32\write.exe).

In fact I wanted to used the same code to open my own executable. once launched, my program has a runtime error and abnormal termination. After some trying I found that when launching the wordpad it has the same problem.

How can I overcome this ?

Many thanks in advance.

preetham
September 24th, 2003, 08:19 AM
did u set the system to interact with the desktop in its properties..

KimSiah Ng
September 24th, 2003, 10:03 PM
Yes, I did. I set the service as system account and enabled interaction with desktop.

Maybe let me tell u what i really want to acheive.
All I want to do is to enable the Administrator account user to
be able to terminate the processes launched by the service using the task manager.

If I simply used createprocess() to launch those processes,
the administrator will not be able to terminate the processes
by the task manager. he will get access denied when trying to
do so. In order to re-start those processes, he need to re-boot the system. Hence I am trying used the service to impersonate as
the Administrator in launching those processes so that
tha Administrator has the right to terminate them.

Is there any other means to achieve this purpose ?

pukys
September 28th, 2003, 04:26 PM
Hmm, thought of the point, that a service is natively *not* attached to a window station?
You've got to open a window station and attach the service process to it, to map the gdi and the desktop into the service process.
For an example look into the msdn documentation on CreateWindowStation and OpenWindowStation.
This describes all issues on user interaction and services.