c# code : How to set windows service as auto start

public bool setAutoStartService(string ServiceName)
{
try
{
string subKey = "SYSTEM\\CurrentControlSet\\Services\\" + ServiceName;
// Setting
RegistryKey rk = baseRegistryKey;
// I have to use CreateSubKey
// (create or open it if already exits),
// 'cause OpenSubKey open a subKey as read-only
RegistryKey sk1 = rk.CreateSubKey(subKey);
// Save the value
sk1.SetValue("Start", (int)2);


}
catch (Exception e)
{

return false;
}
}

No comments:

Post a Comment