Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Services can be disabled using msconfig, and then enabled at a later time.

I found that they can also be enabled or disabled using sc config commands, by setting the start option as disabled or one of boot,system,auto,etc.

How can I create a script or use the command line in a program to determine which start type to use when re-enabling a service?

share|improve this question

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.

share|improve this answer
    
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. –  Dorothy Nov 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.

share|improve this answer
    
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? –  Dorothy Nov 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. –  Dan Nov 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. –  Dan Nov 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. –  Dorothy Nov 2 '11 at 15:25
up vote 1 down vote accepted

I've got it!

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.

share|improve this answer
    
Well done - don't forget to mark this as the answer. –  Dan Nov 2 '11 at 15:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.