I am attempting to start/stop services via a script. The command is
sc stop "service name"
It is failing with this error
{SC} OpenService FAILED 123:

Any assistance would be appreciated.

Dani AI

Generated

reported an {SC} OpenService FAILED 123 error; correctly identified the root cause as a mismatch between the friendly Display Name and the service's internal key (short) name, and reminded that a target machine must be specified for remote operations. The error code 123 corresponds to an invalid name being passed to the Service Control Manager, so SC was simply being asked to open a service that does not exist under the given identifier.

How to resolve and avoid this in scripts:

  • Confirm the service key (short) name shown in the Services console (Services.msc) on the machine. The “Service name” field in the properties is the value the API expects.
  • If you prefer a command-line mapping, use sc getkeyname "Display Name" or a PowerShell query such as Get-Service -DisplayName "Display Name" | Select-Object -ExpandProperty Name to obtain the correct key name for scripting.
  • Check for stray characters or encoding issues in the script (UTF-8 BOM, smart quotes, trailing spaces) that can alter the string passed to SC.
  • Ensure the script runs with appropriate privileges. Remote operations require administrative rights on the target, working RPC/Service Control Manager access, and any required firewall rules enabled.

If problems persist after using the correct key name, verify the service still exists, inspect event logs on the target for more detail, and try a local control attempt on the target host to rule out network or permission issues.

Recommended Answers

All 4 Replies

have you tried:

sc \\servername stop "service name"

And be sure to use the Service Name, not the display name. check via ..
sc query

And be sure to use the Service Name, not the display name. check via ..
sc query

That was it. I used this script several months ago and it worked using the display name. Using the service name as displayed with the query commmand worked. thanks a million.

Occasionally it would, because sometimes Service Name is the same as the Display Name, as you would have noticed.
Cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.