0

I there any way I can use C++ or batch programming to change settings in a windows computer for example enable/disable Services? Or is there a different programming language for that? Which one is better or most commonly used?

  • 1
    What is your specific question. Can you change the settings of Windows within an application, that entirely depends on the setting in question, you provided specifics. What problem exactly are you trying to solve? – Ramhound Aug 31 '15 at 12:08
  • You know sometimes on my or my brothers computer some Services turn off so the volume or network can not work and they should be fixed manually so I was wondering if there's a way I can create a file by using code to automatically do it for us. – Vadim Tatarnikov Aug 31 '15 at 12:11
  • By fixed I mean turned on – Vadim Tatarnikov Aug 31 '15 at 12:12
  • 1
    Update your question so it is specific. – Ramhound Aug 31 '15 at 12:27
1

How do I control Windows Services from a batch file?

for example to enable/disable Services

To disable the service:

sc stop service_name
sc config service_name start= disabled

To enable the service:

sc config service_name start= auto
sc start service_name

Syntax

SC [\\server] [command] [service_name] [Options]

Key

  • server - The machine where the service is running

  • service_name - The KeyName of the service, this is often but not always the same as the DisplayName shown in Control Panel, Services.

    You can get the KeyName by running:

    SC GetKeyName <DisplayName>

commands:

...

  • start START a service.
  • stop STOP a service

...

  • configpermanently change the service configuration

Source sc.


Further Reading

1

A common scripting language to manage windows systems is PowerShell which ships with all windows versions since Vista. Run it by entering Powershell in your start menu search field.

In PowerShell it's easy to start/stop services and it's obvious what you're doing at the same time.

You can list all services like this:

Get-Service

Detailed service information is available, too:

Get-Service -Name wuauserv | Format-List

Name                : wuauserv
DisplayName         : Windows Update
Status              : Running
DependentServices   : {}
ServicesDependedOn  : {rpcss}
CanPauseAndContinue : False
CanShutdown         : True
CanStop             : True
ServiceType         : Win32ShareProcess

Stopping services works like this:

Get-Service -Name wuauserv | Stop-Service

See, the service is now stopped:

Get-Service -Name wuauserv 

Status   Name               DisplayName
------   ----               -----------
Stopped  wuauserv           Windows Update

Guess what the command to start a windows service is called? Right Start-Service and it works just like Stop-Service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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