Dear all,

As i start a service.

It will start in system as a user account .

but i need it will start as a current login as a user.

what i have done

DWORD dwDesiredAccess = SC_MANAGER_CONNECT |
SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS |
STANDARD_RIGHTS_READ ;

if ((schSCManager = OpenSCManager(NULL, NULL, dwDesiredAccess)) ==
NULL)

{
nReturnCode = GetLastError();
}
else
{

SC_HANDLE schService;

if ((schService = OpenService(schSCManager, pszServiceName,
dwDesiredAccess)) == NULL)
{

nReturnCode = GetLastError();

}

if (!StartService(schService, 0, NULL))
{
nReturnCode = GetLastError();
if (nReturnCode == ERROR_SERVICE_ALREADY_RUNNING)
nReturnCode = ERROR_SUCCESS; // not an error
}

}


but it will start this service (pszServiceName) with SYSTEM as user
name

but i need it should start with current login user

thanks in advance.
Edit/Delete Message

Re: problem in creating Services by Igor

Igor
Mon May 28 09:43:25 CDT 2007

<ashukasama@gmail.com> wrote in message
news:1180360805.493774.175280@r19g2000prf.googlegroups.com
> As i start a service.
>
> It will start in system as a user account .
>
> but i need it will start as a current login as a user.

The whole point of a service is to be able to run while _no_ user is
logged in. That's why you cannot set it up to run as logged in user
(what if there's none? What if there's more than one?).

If you want your code to run under launching user's account, make it a
regular executable rather than a service.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: problem in creating Services by Marc

Marc
Wed May 30 02:22:31 CDT 2007

On May 28, 7:00 am, ashukas...@gmail.com wrote:
> As i start a service.
>
> It will start in system as a user account .
>
> but i need it will start as a current login as a user.
>
> what i have done
...
> but it will start this service (pszServiceName) with SYSTEM as user
> name
> but i need it should start with current login user

Your code looks fine and will start the service but as you noticed, it
runs under the system account. If you need to have the service run
under a user account then run services.msc (from a command prompt or
start / run), double click on your service, and in the Log On tab,
change it from "Local System account" to "This Account" and enter the
user-name / password to use. Note that the service will start when
the system is booted and that it has nothing to do with users logging
in/out on the console.

Marc