Installing a Windows Service programmatically | |
Hi all,
I read an article from http://www.c-sharpcorner.com/Code/20...mmatically.asp
about how to install a windows service programmatically.
Based on the code sample, it provides the feature to install
service
under LocalSystem account.
What I need is to install service under NT
AUTHORITY\NetworkService, so that my service can access the shared
network resources.
What I had done for this is to call
CreateService(sc_handle, serviceName, serviceDisplayName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
servicePath, null, 0, null, @NT AUTHORITY\NetworkService, "");
But the problem is that, the service is installed under LocalSystem
account inspite of being passing the parameter value as non-null.
Please help me. | | | | re: Installing a Windows Service programmatically
sunil wrote: Quote:
Hi all,
I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/...
about how to install a windows service programmatically.
Based on the code sample, it provides the feature to install
service
under LocalSystem account.
What I need is to install service under NT
AUTHORITY\NetworkService, so that my service can access the shared
network resources.
What I had done for this is to call
CreateService(sc_handle, serviceName, serviceDisplayName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
servicePath, null, 0, null, @NT AUTHORITY\NetworkService, "");
>
But the problem is that, the service is installed under LocalSystem
account inspite of being passing the parameter value as non-null.
Please help me.
Hi,
I believe there's a property in your Service object or ServiceInstaller or
something that specifies which account the service should run under, have
you got this set to "NetworkService"?
--
Hope this helps,
Tom Spink
Google first, ask later. | | | | re: Installing a Windows Service programmatically
"sunil" <sairaj.sunil@gmail.comwrote in message
news:1160024811.483947.56540@m7g2000cwm.googlegrou ps.com...
| Hi all,
| I read an article from
| http://www.c-sharpcorner.com/Code/20...mmatically.asp
| about how to install a windows service programmatically.
| Based on the code sample, it provides the feature to install
| service
| under LocalSystem account.
| What I need is to install service under NT
| AUTHORITY\NetworkService, so that my service can access the shared
| network resources.
| What I had done for this is to call
| CreateService(sc_handle, serviceName, serviceDisplayName,
| SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
| SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
| servicePath, null, 0, null, @NT AUTHORITY\NetworkService, "");
|
| But the problem is that, the service is installed under LocalSystem
| account inspite of being passing the parameter value as non-null.
| Please help me.
|
If by NT you mean NT4, you won't be able to do it, LocalService and
NetworkService service accounts, were introduced in W2K. Note also that
NetworkService (just like LocalSystem) has network access only in a W2K
domain (AD) realm.
Your options are:
- impersonate while accessing the network resource,
- run your service as a domain user (NT4 domain),
- or get rid of NT4.
Willy. | | | | re: Installing a Windows Service programmatically Quote:
Hi,
>
I believe there's a property in your Service object or ServiceInstaller or
something that specifies which account the service should run under, have
you got this set to "NetworkService"?
Hi Tom,
I have passed the value @NT AUTHORITY\NetworkService for the
lpServiceStartName and the password is empty as can be seen in the
call:
CreateService(sc_handle, serviceName, serviceDisplayName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
servicePath, null, 0, null, @NT AUTHORITY\NetworkService, "");
Thanks for the reply | | | | re: Installing a Windows Service programmatically
Willy Denoyette [MVP] wrote: Quote:
If by NT you mean NT4, you won't be able to do it, LocalService and
NetworkService service accounts, were introduced in W2K. Note also that
NetworkService (just like LocalSystem) has network access only in a W2K
domain (AD) realm.
Your options are:
- impersonate while accessing the network resource,
- run your service as a domain user (NT4 domain),
- or get rid of NT4.
>
>
Willy.
Hi,
I am not asking about NT4. I am asking about running the service on
WInXP service pack2 prof.
I thought that, to create a NetworkService programmatically, i have to
call CreateService as I have written in my previous post. Am I correct?
Thanks | | | | re: Installing a Windows Service programmatically
"sunil" <sairaj.sunil@gmail.comwrote in message
news:1160103513.653024.289720@h48g2000cwc.googlegr oups.com...
|
| Willy Denoyette [MVP] wrote:
| If by NT you mean NT4, you won't be able to do it, LocalService and
| NetworkService service accounts, were introduced in W2K. Note also that
| NetworkService (just like LocalSystem) has network access only in a W2K
| domain (AD) realm.
| Your options are:
| - impersonate while accessing the network resource,
| - run your service as a domain user (NT4 domain),
| - or get rid of NT4.
| >
| >
| Willy.
| Hi,
| I am not asking about NT4. I am asking about running the service on
| WInXP service pack2 prof.
| I thought that, to create a NetworkService programmatically, i have to
| call CreateService as I have written in my previous post. Am I correct?
| Thanks
|
Yes, but you don't even have to write a custom installer yourself, all
system higher than W2K come with a commandline utility, called sc.exe, which
offers all you need to install configure and control your service
applications. Just start sc /help from the command prompt and check the
options.
Willy. | | | | re: Installing a Windows Service programmatically Quote:
>
Yes, but you don't even have to write a custom installer yourself, all
system higher than W2K come with a commandline utility, called sc.exe, which
offers all you need to install configure and control your service
applications. Just start sc /help from the command prompt and check the
options.
>
I know about that utility.That will do in case of a standalone service.
But in my case, I have to interact with the user.
For this purpose, I have 2 projects in my application. One project is a
console application and should run as a service, whereas the other is a
Windows forms application that interacts with the user and uses the
newly installed service.
Considering this scenario, how can I make the console application as a
network service rather than running under LocalSystem account. Please
tell me how to do this? | | | | re: Installing a Windows Service programmatically
"sunil" <sairaj.sunil@gmail.comwrote in message
news:1160197203.552432.315180@e3g2000cwe.googlegro ups.com...
|
| >
| Yes, but you don't even have to write a custom installer yourself, all
| system higher than W2K come with a commandline utility, called sc.exe,
which
| offers all you need to install configure and control your service
| applications. Just start sc /help from the command prompt and check the
| options.
| >
| I know about that utility.That will do in case of a standalone service.
| But in my case, I have to interact with the user.
| For this purpose, I have 2 projects in my application. One project is a
| console application and should run as a service, whereas the other is a
| Windows forms application that interacts with the user and uses the
| newly installed service.
| Considering this scenario, how can I make the console application as a
| network service rather than running under LocalSystem account. Please
| tell me how to do this?
|
Ok, first of all, a console application is not a windows service and can
never run as such. If you need a windows service you have to create a
"service project" from VS. You can include a service installer component by
which you can set the service account to run the service.
If you don't include a service installer component into your service, you
will have to use separate installer like sc.exe.
Second, while you can arrange to run a service from the commandline, you
have to keep in mind that the context the console 'service' runs in is not
the same as it would run as a 'Windows service'.
For instance, while a service can run as 'localsystem', network service' or
'local service', a console application cannot, it always runs in the context
of the interactive user.
Willy. |  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|