Change windows settings via code

5,212

Solution 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

Solution 2

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.

Share:
5,212

Related videos on Youtube

John Smith
Author by

John Smith

Updated on September 18, 2022

Comments

  • John Smith
    John Smith over 1 year

    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?

    • Ramhound
      Ramhound over 8 years
      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?
    • John Smith
      John Smith over 8 years
      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.
    • John Smith
      John Smith over 8 years
      By fixed I mean turned on
    • Jay
      Jay over 8 years
    • John Smith
      John Smith over 8 years
      And can I use commands in a batch file to speed the process up or something, I don't really get it
    • Ramhound
      Ramhound over 8 years
      Update your question so it is specific.