3 Answers
3

What would you need to determine? Whether or not it's already set to the type you want to set it to?

It really doesn't matter what the current state is. If you are "re-enabling" a service by setting it's startup type to Automatic and it's already set to Automatic then no change will ocurr, so you really don't need to determine what it's current state is.

If the services start value was set to auto and then set to disabled I don't know which of the 5 enable options to set it to when re-enabling. I am not setting it to what it already is. I am setting it to the enabled value that it once was. Which is what msconfig does.
–
DorothyNov 2 '11 at 14:03

I don't think there's any native way to do this. The only way to do it would be to export the state when you disable it and then re read it from a config file when you enable it. You may have better luck on StackOverflow with this one.

What O/S are you on? Powershell may be a better bet. You can Google "Get-Service" to get you started.

I am using Windows 7 and Vista. I will be working on XP later. According to my tests, msconfig knows which enabled setting to set the service to. How is msconfig doing it? Perhaps the information is in the registry?
–
DorothyNov 2 '11 at 14:13

I really don't know - but you're probably better off replicating it yourself rather than try and piggy back whatever method they're using.
–
DanNov 2 '11 at 15:06

There is data about the startup type in the registry, at HKLM\System\CurrentControlSet\services but this is changed when you disable it.
–
DanNov 2 '11 at 15:07

Actually I was already reading that location. I found it easier then using sc. And I figured it out. The location is HKLM\Software\Microsoft\Shared Tools\MSConfig\services. I have an answer you can read.
–
DorothyNov 2 '11 at 15:25

After some testing and research I discovered the location in the registry where msconfig stores the past enabled start value as well as the disabled date.

HKLM\Software\Microsoft\Shared Tools\MSConfig\services

It consists of sub keys for each disabled service and each sub key has the following values: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND as well as the short name of the disabled service who's data contains one of the following:

0 = boot

1 = system

2 = auto

3 = demand

5 = delayed-auto

All I have to do is read and write here when enabling and disabling services.

FYI: 4 = disabled. That's why it is not in the list above. Only keys which are currently disabled are listed in that location. And I don't think XP has 5.