Change windows settings via code
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
...
config
permanently change the service configuration
Source sc.
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- sc - Service Control - Create, Start, Stop, Query or Delete any Windows SERVICE.
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
.
Related videos on Youtube
John Smith
Updated on September 18, 2022Comments
-
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 over 8 yearsWhat 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 over 8 yearsYou 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 over 8 yearsBy fixed I mean turned on
-
Jay over 8 years
-
John Smith over 8 yearsAnd can I use commands in a batch file to speed the process up or something, I don't really get it
-
Ramhound over 8 yearsUpdate your question so it is specific.
-