473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.

Oct 5 '06 #1
7 4314
sunil wrote:
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.
Oct 5 '06 #2

"sunil" <sa**********@gmail.comwrote in message
news:11*********************@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.
Oct 5 '06 #3

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

Oct 5 '06 #4

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

Oct 6 '06 #5

"sunil" <sa**********@gmail.comwrote in message
news:11**********************@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.

Oct 6 '06 #6
>
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?

Oct 7 '06 #7

"sunil" <sa**********@gmail.comwrote in message
news:11**********************@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.


Oct 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jack | last post by:
When trying to install a newlydeveloped windows service to a Windows 2000 Server, I get the following error message: InstallUtilLib.dll:ClrCreateManagedInstance (hr=0x800700002): The system...
2
by: Vince Keller | last post by:
I dont know if this is the correct newsgroup to post questions on Windows Service. I am trying to install and uninstall a Windows Service programmatically. As far as I know, there isnt a class...
9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
1
by: Bhavya Shah | last post by:
Hello, I want to install an application as a Windows Service on a remote computer. I know the procedure to install a windows service on a local computer by using installutil.exe. How can I...
2
by: Strahimir Antoljak | last post by:
I am creating a new windows service and I would like to control its Recovery property. On a system administrator level the Recovery property is found in Control Panel -> Administrative Tools ->...
2
by: John | last post by:
Hi I am trying to install a windows service exe file. I have the following command line; c> installutil.exe webservice1.exe This did its thing but the windows service did not appear in the...
4
by: Ankit Aneja | last post by:
I am able to make a windows service in C#.NET and also tested it on my own system by installing it this way(installutil servicename.exe) and is running fine now when I want to test it on other...
0
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi All I would like to install the same Windows Service project on the same server under different names, one for each customer. I have been able to do it but I would like an expert opinion as...
0
by: msalman | last post by:
Hey I created a windows service and added it to a setup project. The setup project should install the service and run it but for some reasons it doesn't install the service and gives following...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.