Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I use this code scheme to disable or enable Windows services:

var process = Process.Start("sc.exe", "config syncagentsrv start= disabled");


But I'm having trouble deactivating a service because it has spaces in its name:
Tib Mounter Service

What I have tried:

I've tried several ways, like the ones below, but none works:

var process = Process.Start("sc.exe", "config Tib Mounter Service start= disabled");

var process = Process.Start("sc.exe", "config 'Tib Mounter Service' start= disabled");
Posted
Updated 5-Jun-21 4:30am

1 solution

Surround the name with double quotes, not single, just like you do on the command line. But, in C#, you have to escape the quotes so they become part of the string:
C#
var process = Process.Start("sc.exe", "config ""Tib Mounter Service"" start= disabled");
 
Share this answer
 
Comments
Lazie Wouters 2021 5-Jun-21 12:08pm    
Thank you so much. It worked! I had been burning my neurons for weeks after this solution! Thanks buddy!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900