CreateProcess from service

Hello,
I am using CreateProcess function from within Windows Service and want to launch Internet Explorer. But whenever I launch it then I get a dialog box (when first time Internet Explorer is run on system then we get a dialog box to enter IE settings, same dialog box appear in this case). I don't want this dialog boz to appear. Same code works fins in Dialog Based application. I don't know what are the rights problem with Windows Services. Please help me.
haiderAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jkrConnect With a Mentor Commented:
'Tokens' don't have privileges - once you have a security token, you can impersonate the owner of that token, calling 'ImpersonateLoggedOnUser()' does not require any special privilege...
0
 
jkrCommented:
>>I don't know what are the rights problem with Windows
>>Services

http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0398/service2.htm&nav=/msj/0398/newnav.htm

("Why Do Certain Win32 Technologies Misbehave in Windows NT Services?")

You get the dialog box because the service runs under a different user account. "Impersonate" the user that is logged on to avoid that.

0
 
haiderAuthor Commented:
But how to do that. Please give me some clue.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jkrCommented:
Well, what you need to do is

LogonUser();
ImpersonateLoggedOnUser();

// do stuff

RevertToSelf();

E.g.:

   HANDLE          hToken  =   NULL;

   if  (   !LogonUser  (   ( char*) pszUsername,
                           NULL,
                           ( char*) pszPwd,
                           LOGON32_LOGON_INTERACTIVE,
                           LOGON32_PROVIDER_DEFAULT,
                           &hToken
                       )
       )
       {
           return  (   GetLastError    ());
       }

   if  (   !ImpersonateLoggedOnUser    (   hToken)
       )
       {
           return  (   GetLastError    ());
       }

You alternatively could obtain a token from a process the user is running (explorer.exe is a good choice <s>). You'll nedd the PID to call 'OpenProcess()', then 'OpenProcessToken()' with 'TOKEN_IMPERSONATE' access. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175030 ("HOWTO: Enumerate Applications Using Win32 APIs (Q175030)") on how to get that PID - it comes with sample code.
0
 
haiderAuthor Commented:
LogonUser(); function returs ERROR_PRIVILEGE_NOT_HELD error???
0
 
jkrCommented:
You have to assign the "SE_TCB_NAME" privilege to the account the service is running under (this is mentioned in the docs, BTW)
0
 
haiderAuthor Commented:
I tried to "AdjustTokenPrivileges" use function, but I m getting error. How can I set "SE_TCB_NAME" privilege to service???
0
 
jkrCommented:
The easiest way is to open the user manager and do it from there.
0
 
haiderAuthor Commented:
Can u please explain it clearly. I want to do all these things programatically. Please ....
0
 
jkrCommented:
Have you tried what I mentioned about getting the user token from a user process? You cannot hardcode every user's password anyway, and setting privileges from within code isn't trivial at all...
0
 
haiderAuthor Commented:
But if I get user token from a user process, then will this token have privileges that I require???
0
 
jkrCommented:
Well, anything new?
0
 
haiderAuthor Commented:
Thats really gr8 and it works. I use "OpenProcess" for "explorer.exe" and then I use "ImpersonateLoggedOnUser".

Thanx!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.