sc.exe is a standard Windows CLI (console application) that manages Windows services. Use this tag for questions regarding sc.exe.
Questions tagged [sc.exe]
16 questions
34
votes
3 answers
How do i invoke sc create from a powershell script
I want to invoke sc create from a powershell script. Here is the code.
function Execute-Command
{
param([string]$Command, [switch]$ShowOutput=$True)
echo $Command
if ($ShowOutput) {
Invoke-Expression $Command
} else {
…

gyozo kudor
- 6,284
- 10
- 53
- 80
8
votes
2 answers
ServiceControlHandler used for usb device notifications, OnStop() not implementable
I'd like to write a service that listens for device notifications (USB media plugged in, removed). The problem of listening for device notifications in a C# service is, that System.Windows.Forms.Control.WndProc isn't available because a windows…

wullxz
- 17,830
- 8
- 32
- 51
3
votes
1 answer
Setting a Windows Service's 'Enable actions for stops with errors' check box via command line
I am trying to find a commandline method for setting the Enable actions for stops with errors check box in the Recovery tab of a service's properties dialogue.
I know that when I change the value of the check box and hit apply, in the registry the…

Bill Hurt
- 749
- 1
- 8
- 26
2
votes
1 answer
Remote OpenSCManager fails with access denied
I am attempting to control a service on a remote machine using the following code:
// Error checking omitted for brevity
HANDLE hToken = NULL;
// user = username with no domain specification
// domain = targetmachine when targetting computer outside…

villintehaspam
- 8,540
- 6
- 45
- 76
1
vote
1 answer
Windows SC.exe how to query control codes on a service
What I Have Done
I am trying to implement ServiceBase.OnCustomCommand(int command) in a custom Windows Service called MyTestService, with custom command codes as done in this answer:
public enum MyCustomCommands { ExecuteScript = 128 };
I noticed…

Intrastellar Explorer
- 3,005
- 9
- 52
- 119
1
vote
0 answers
My Windows Service Won't restart on Failure as stated in the script "sc.exe" Windows
I have a service well running and configured on my windows OS The service runs as the PC starts, but some times it crashes when there is no internet connection on PC boot and due to that, it does not start at all. My goal is to let that service…

John Code
- 655
- 7
- 24
0
votes
0 answers
Inno Setup uninstaller always freeze after execute Windows Service Manager to remove a service
I'm trying to remove a service of my program when the uninstall is executed, I'm using the UninstallRun section, the problem happens after Inno execute the service control process, that hangs my uninstaller, the code:
[UninstallRun]
Filename:…

cYeR
- 145
- 1
- 10
0
votes
0 answers
sc.exe using variable parameters
This is a bit of an odd one, but I am trying to figure out how to use sc.exe with variable parameters. Powershell 7.X does not support Set-Service password changes for remote services. However, you can still do so via sc.exe …

sbagnato
- 603
- 3
- 11
- 35
0
votes
1 answer
Service Control Manager (sc.exe) fails when using a localhost alias in hosts file, but succeeds when using the loopback address directly
I am running the command:
sc \\My-Server create TestService binPath= "C:\Test\Test.exe"
However, it fails with
[SC] OpenSCManager FAILED 5:
Access is denied.
My hosts file contains:
127.0.0.1 My-Server
However, if I do the command below, it…

Eza
- 43
- 6
0
votes
1 answer
Return back rights to set security descriptor for SCManager
On Windows server 2016 I made an incautious action. Using my account which belong to a builtin Administrator group I set security descriptor for SCManager:
sc sdset scmanager…

Vitaliy
- 1
0
votes
1 answer
querying the state of multiple Windows services without an external file
I have to use sc.exe to log the state of a few services to a text file.
I cannot use an external text, or ini file to list my windows services.
So whilst the following works:
for /f "delims=" %%A in (list.txt) do sc query %%A >>…

sss
- 5
- 3
0
votes
1 answer
Trying to install service programatically from VB.Net application - Calls to SC.exe fail
I have a config program and a bunch of services that run per configured device. In my config program when a device to monitor is added I create a service with a ID using something like this:
Dim appPath As String =…

ADY
- 101
- 1
- 9
0
votes
1 answer
Can't stop my custom windows service via gitlab-runner
This is my first question on stackoverflow. Hope your eyes won't be bleeding too much from my English.
Long story short: I can't stop my custom windows service via gitlab-runner.
What I'm trying to achieve during gitlab CI\CD is:
send a signal to…

Mikhail 89
- 26
- 4
0
votes
0 answers
How can I read the 'sc.exe' start value of a service with C#?
I can change the start value of a service with the command
sc config start=
But how can I find out how the starting value is currently set?

JustSpruce
- 3
- 2
0
votes
1 answer
WIX: Install Services using runner and multible dlls
I'm working on a Wix installer which should install multiple Services based on the same runner. This a some dlls which will be loaded by the runner. With sc.exe this works fine on my test system. Now my question, can I use standard Wix…

AndyO
- 19
- 2