Change Startup Type of Windows Service

Hi,

I was wondering if anyone knows if it possible to change the startup type of a service programatically, either within the service itself or using a service conrtoller?

Thanks

Ryan

[190 byte] By [RyanSmith] at [2007-12-16]
# 1
I believe this is a registry entry. I would go through the registryusing regedit searching for string names of specific services in services.msc
MarcD at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
From Service Controller:
Control Panel....Computer Management....Services
DMan1 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3

Hi Ryan,

Service startup type is set during installation (see
ServiceInstaller.StartType).There is currently no managed way to
change this after installation.

However you can change it programmatically in code:


using System;
using Microsoft.Win32;

public enum ServiceStart
{
Boot = 0,
System = 1,
Automatic = 2,
Manual = 3,
Disabled = 4
}

public class ServiceController2 : System.ServiceProcess.ServiceController
{

public ServiceStart ServiceStart
{
get
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(
"SYSTEM\\CurrentControlSet\\Services\\" + this.ServiceName );
ServiceStart start = (ServiceStart)key.GetValue("Start");
key.Close();
return (start);
}
set
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(
"SYSTEM\\CurrentControlSet\\Services\\" + this.ServiceName, true );
key.SetValue( "Start", (int)value );
key.Close();
}
}
}
}



Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified