Share via

ServiceController.StartType equivalent

OSVBNET 1,401 Reputation points
2022-06-18T21:04:06.053+00:00

Hello,
To have the new StartType property in ServiceController, need to upgrade to .net 4.6.1 or higher.
But can simply:
MyKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\blah", False)
MyKey.GetValue("Start")

My question is that the registry method is as reliable as the first one?
My app is always running in admin mode so no problem here (requireAdministrator)
But any condition that the registry method fails?

And this registry method works on all Windows versions or there are exceptions?

Can't upgrade to .net 4.6.1 or above :(
Thanks in advance

Developer technologies | VB
0 comments No comments

Answer accepted by question author

RLWA32 52,571 Reputation points
2022-06-18T22:37:03.73+00:00

I think you are safe setting the service start mode via the registry. I haven't checked all versions of Windows but the indicated registry key/value pair is valid as far back as Windows XPSP3.

And under the hood, the Windows API function CreateService sets the start mode of the service and the minimum supported desktop version of Windows is XP. And if you wanted to change the start mode for an existing service you could p/invoke ChangeServiceConfig to avoid direct registry editing.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.