Disabling a service

  • Thread starter Thread starter Hugh Janus
  • Start date Start date
H

Hugh Janus

Hi all.

I am using the ServiceController class to interface with a service on a
Windows 2003 Server. However, I cannot work out how to disable the
service or set it to manual. Starting it and stopping it works fine
but of course, after rebooting, the service restarts because it is set
to Auto.

Any ideas on how to do this? I would rather not use WMI unless there
is not alternative simply because I can do everything else without it!

Thanks.
 
In the projectInstaller.vb, in the properties of the serviceinstaller,
set the startup to manual instead of automatic...

To disable the service i think you must uninstall it... you can run a
..bat file with a call to the installutil.exe /u

Good Luck :)
 
Sorry, I guess I did not make myself clear. The app I am writing is
*not* a windows service, but a normal app. It interfaces with various
windows services that I need to manipulate. I need to disable one of
these windows services as it is no longer required but i do not want to
uninstall it.
 
Hugh,
Unfortunately (or is it fortunately) you cannot. As ServiceController is
really intended to manipulate the current instance of an *existing* service,
not the configuration of a service.

I know ServiceInstaller can, as it is intended to configure a service when
you install it. ServiceInstaller may be over kill in this case. My concern
with ServiceInstaller is changing more config then one should.

I'm not sure if WMI can change the configuration of a service.

I suspect you will need to call the Win32 API, unfortunately I don't have
examples of calling said Win32 API... If I find a sample or the API itself

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi all.
|
| I am using the ServiceController class to interface with a service on a
| Windows 2003 Server. However, I cannot work out how to disable the
| service or set it to manual. Starting it and stopping it works fine
| but of course, after rebooting, the service restarts because it is set
| to Auto.
|
| Any ideas on how to do this? I would rather not use WMI unless there
| is not alternative simply because I can do everything else without it!
|
| Thanks.
|
 
The Win32 API you're looking for is ChangeServiceConfig
You can pass null (IntPtr.Zero) for most parameters

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top