Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

sc.exe is a command line tool for manipulating services on windows. E.g. to list all the services on your machine you can type sc query from a command prompt. However, if you do it from powershell, it instead executes Set-Content because sc is an alias for Set-Content. Even & sc will execute the alias.

How do I run sc.exe from a powershell prompt?

share|improve this question

2 Answers 2

You can do what Justin answered or you can create your own alias for the command. it depends if you need to use the command often throughout a session. If you don't, just listen to Justin. If you do, aliasing isn't a bad idea.

Locate the sc.exe executable that you would like to use. (We'll assume it's in the root of your C:\ drive for now.)

Create the PowerShell alias with the following command:

Set-Alias <What you want to use as an alias> <Path to executable or one of the commands Justin proposed>

For example:

Set-Alias sc2 "C:\cs.exe"

These aliases will disappear when you close PowerShell, export them like so:

Export-Alias "C:\Myaliases.txt"

Then import them when you need to use them (disregard all the errors that show, these errors are due to the fact that PowerShell tries to restore all aliases, including those that are built-in. Of course, these already exist so they are ignored.)

Import-Alias "C:\Myaliases.txt"

More documentation on PowerShell aliasing available on MSTN.

share|improve this answer
    
That's a good point. I edited you answer since sc comes with windows and you can use the systemroot environment variable to locate it. –  Justin Dearing Feb 27 '12 at 16:07
    
@JustinDearing I don't see any (pending) edits... And I do get what you mean about the systemroot. However, not everyone who will come here will be looking for sc specific. Therefore, the answer is now applicable to other aliased executables as well. Built-in or not. –  BloodPhilia Feb 27 '12 at 16:08

You have two options, you can either use cmd /c sc query or sc.exe query.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.