{"id":513,"date":"2014-04-30T00:20:26","date_gmt":"2014-04-30T07:20:26","guid":{"rendered":"http:\/\/www.coretechnologies.com\/blog\/?p=513"},"modified":"2014-04-30T00:20:26","modified_gmt":"2014-04-30T07:20:26","slug":"essential-tools-windows-services-sc-exe","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/windows-services\/essential-tools-windows-services-sc-exe\/","title":{"rendered":"Essential Tools for Windows Services: SC.EXE"},"content":{"rendered":"<p>While the useful <a href=\"\/blog\/windows-services\/essential-tools-for-windows-services-net-command\/\">NET.EXE<\/a> utility is great for starting an stopping windows services, it cannot do much beyond that. Enter Microsoft&#8217;s SC.EXE &#8211; a versatile command-line utility built into Windows that can help you start, stop, restart or configure any Windows Service.<\/p>\n<p>Type <b>SC<\/b> at a command prompt to see the extensive set of options available:<\/p>\n<pre style=\"background-color:#F4F4F4\">\nDESCRIPTION:\n        SC is a command line program used for communicating with the\n        Service Control Manager and services.\nUSAGE:\n        sc &lt;server&gt; [command] [service name] &lt;option1&gt; &lt;option2&gt;...\n        The option <server> has the form \"\\\\ServerName\"\n        Further help on commands can be obtained by typing: \"sc [command]\"\n        Commands:\n          query-----------Queries the status for a service, or\n                          enumerates the status for types of services.\n          queryex---------Queries the extended status for a service, or\n                          enumerates the status for types of services.\n          start-----------Starts a service.\n          pause-----------Sends a PAUSE control request to a service.\n          interrogate-----Sends an INTERROGATE control request to a service.\n          continue--------Sends a CONTINUE control request to a service.\n          stop------------Sends a STOP request to a service.\n          config----------Changes the configuration of a service (persistent).\n          description-----Changes the description of a service.\n          failure---------Changes the actions taken by a service upon failure.\n          failureflag-----Changes the failure actions flag of a service.\n          sidtype---------Changes the service SID type of a service.\n          privs-----------Changes the required privileges of a service.\n          qc--------------Queries the configuration information for a service.\n          qdescription----Queries the description for a service.\n          qfailure--------Queries the actions taken by a service upon failure.\n          qfailureflag----Queries the failure actions flag of a service.\n          qsidtype--------Queries the service SID type of a service.\n          qprivs----------Queries the required privileges of a service.\n          qtriggerinfo----Queries the trigger parameters of a service.\n          qpreferrednode--Queries the preferred NUMA node of a service.\n          delete----------Deletes a service (from the registry).\n          create----------Creates a service. (adds it to the registry).\n          control---------Sends a control to a service.\n          sdshow----------Displays a service's security descriptor.\n          sdset-----------Sets a service's security descriptor.\n          showsid---------Displays the service SID string corresponding to\n                          an arbitrary name.\n          triggerinfo-----Configures the trigger parameters of a service.\n          preferrednode---Sets the preferred NUMA node of a service.\n          GetDisplayName--Gets the DisplayName for a service.\n          GetKeyName------Gets the ServiceKeyName for a service.\n          EnumDepend------Enumerates Service Dependencies.\n\n        The following commands don't require a service name:\n        sc &lt;server&gt; &lt;command&gt; &lt;option&gt;\n          boot------------(ok | bad) Indicates whether the last boot should\n                          be saved as the last-known-good boot configuration\n          Lock------------Locks the Service Database\n          QueryLock-------Queries the LockStatus for the SCManager Database\n<\/pre>\n<h2><b>Stopping\/Starting a Service with SC<\/b><\/h2>\n<p>To stop a windows service from an <a href=\"http:\/\/windows.microsoft.com\/en-us\/windows\/command-prompt-faq#1TC=windows-7\" target=\"_blank\" rel=\"noopener noreferrer\">elevated DOS prompt<\/a>, run:<\/p>\n<blockquote><p><b>SC STOP &lt;Service-Name&gt;<\/b><\/p><\/blockquote>\n<p>where &lt;Service-Name&gt; is the <a href=\"\/WindowsServices\/FAQ.html#FindServiceName\" target=\"_blank\" rel=\"noopener noreferrer\">name of the service<\/a>. Be sure to enclose the name in quotes if it contains a space!\n<\/p>\n<p>\nFor example, to stop the Print Spooler service (named &#8220;Spooler&#8221;), run:<\/p>\n<blockquote><p><b>SC STOP Spooler<\/b><\/p><\/blockquote>\n<p><a href=\"\/blog\/images\/sc-stop-spooler-service-677x343.gif\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"SC: Stopping the Print Spooler Service\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/sc-stop-spooler-service-677x343.gif\" border=\"0\" title=\"SC: Stopping the Print Spooler Service (click to enlarge)\" alt=\"SC: Stopping the Print Spooler Service\" width=\"560\" \/><br \/>\n<\/a><\/p>\n<p>Notice that the SC command will simply <b>make a request for the service to stop and return immediately, before the service has actually stopped<\/b>. This is evidenced by the STOP_PENDING state (which means that the service is in the process of winding down) returned in the screenshot above. If you plan to use this command in a batch file, you may need to add a sleep\/pause after calling SC to give the service some time to respond. (The <a href=\"\/blog\/windows-services\/essential-tools-for-windows-services-net-command\/\">NET.EXE command<\/a>, which will wait\/block until the service has completely stopped, may be a better choice in this respect.)\n<\/p>\n<p>Similarly, to start a windows service, use:<\/p>\n<blockquote><p><b>SC START &lt;Service-Name&gt;<\/b><\/p><\/blockquote>\n<p>Again, the request will be made but SC will not wait for the service to complete its startup before returning.<\/p>\n<h2><b>Using SC to Check the Status of a Service<\/b><\/h2>\n<p>To discover the state of your service, run SC with the QUERYEX option:<\/p>\n<blockquote><p><b>SC QUERYEX &lt;Service-Name&gt;<\/b><\/p><\/blockquote>\n<p>\nCheck on the Spooler service like this:<\/p>\n<blockquote><p><b>SC QUERYEX Spooler<\/b><\/p><\/blockquote>\n<p><a href=\"\/blog\/images\/sc-check-spooler-service-677x343.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"SC: Checking the Print Spooler Service\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/sc-check-spooler-service-677x343.png\" border=\"0\" title=\"SC: Checking the Print Spooler Service (click to enlarge)\" alt=\"SC: Checking the Print Spooler Service\" width=\"560\" \/><br \/>\n<\/a><\/p>\n<p>If the service is running, SC will return the underlying process identifier (&#8220;PID&#8221;) which can be used to manipulate the service&#8217;s process. This is very handy information when a service is stuck or unresponsive and must be <a href=\"\/WindowsServices\/FAQ.html#StuckPending\" target=\"_blank\" rel=\"noopener noreferrer\">forcibly terminated<\/a>!<\/p>\n<h2><b>Disabling a Service<\/b><\/h2>\n<p>The <b>CONFIG<\/b> option enables you to modify a service&#8217;s settings. If you wish to disable a naughty service, preventing anyone from starting it, type:<\/p>\n<blockquote><p><b>SC CONFIG &lt;Service-Name&gt; start= disabled<\/b><\/p><\/blockquote>\n<p>For example, this command disables the infamous <a href=\"\/WindowsServices\/FAQ.html#DisableInteractiveServicesDialog\" target=\"_blank\" rel=\"noopener noreferrer\">Interactive Services Detection Service<\/a> (named &#8220;UI0Detect&#8221;):<\/p>\n<blockquote><p><b>SC CONFIG UI0Detect start= disabled<\/b><\/p><\/blockquote>\n<p>Note that the space in between &#8220;start=&#8221; and &#8220;disabled&#8221; is required!<\/p>\n<h2><b>How to Create a New Service with SC<\/b><\/h2>\n<p>SC can be used to create a new service as well. Type &#8220;SC CREATE&#8221; to see the many settings that can be applied but at a minimum you must specify:<\/p>\n<ul>\n<li>the name of the service,<\/li>\n<li>the display name of the service (a more descriptive moniker),<\/li>\n<li>the full path to the executable hosting the service<\/li>\n<\/ul>\n<p>For example, the following command creates a service called &#8220;MyService&#8221; with an executable located in &#8220;C:\\MyService\\MyService.exe&#8221;:<\/p>\n<blockquote><p><b>SC CREATE MyService binPath= &#8220;C:\\MyService\\MyService.exe&#8221; DisplayName= &#8220;My very cool service&#8221;<\/b><\/p><\/blockquote>\n<p>Once installed, you can work with the new service as normal in the Services application:<br \/>\n<a href=\"\/blog\/images\/sc-new-service-created-911x662.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"SC: New Service Created\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/sc-new-service-created-911x662.png\" border=\"0\" title=\"SC: New Service Created (click to enlarge)\" alt=\"SC: New Service Created\" width=\"560\" \/><br \/>\n<\/a><\/p>\n<p>Note that only executables explicitly written to interface with the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Service_Control_Manager\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Windows Service Control Manager<\/a> should be installed this way. While SC will happily accept a regular, non-service binary, you will receive the fatal <a href=\"http:\/\/support.microsoft.com\/kb\/886695\" target=\"_blank\" rel=\"noopener noreferrer\">Error 1053<\/a> when you attempt to start the service. Employ a service wrapper like <a href=\"\/products\/AlwaysUp\/\" target=\"_blank\" rel=\"noopener noreferrer\">AlwaysUp<\/a> in that situation.<\/p>\n<h2><b>Using SC to Delete a Service<\/b><\/h2>\n<p>The command to remove a service with SC is straightforward:<\/p>\n<blockquote><p><b>SC DELETE &lt;Service-Name&gt;<\/b><\/p><\/blockquote>\n<p>To discard the service named &#8220;MyService&#8221; that we installed above, use:<\/p>\n<blockquote><p><b>SC DELETE MyService<\/b><\/p><\/blockquote>\n<p>Needless to say, please use this command with caution!. Once a service is deleted it cannot be easily re-instated. <b>Removing the wrong service can render your computer unusable!<\/b><\/p>\n<h2><b>SC is the Complete Command Line Utility for Windows Services<\/b><\/h2>\n<p>So whenever you need to work with a service via a batch file or from a DOS command prompt, look to SC for support. This versatile, essential tool has earned its reputation as the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Swiss_Army_knife\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">&#8220;Swiss Army Knife&#8221;<\/a> for Windows Services! <\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/access-session-0-with-vnc\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"How to Use VNC to Remotely Access Session 0 (with Keyboard and Mouse!)\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/vnc-logo-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">How to Use VNC to Remotely Access Session 0 (with Keyboard and Mouse!)<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/windows-services-no-significant-changes-in-windows-8-and-windows-server-2012\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Windows Services: No Significant Changes in Windows 8 and Windows Server 2012\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/windows-logo-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Windows Services: No Significant Changes in Windows 8 and Windows Server 2012<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/trouble-running-batch-file\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Why can&#039;t AlwaysUp run my Batch File?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/gear-window-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Why can&#039;t AlwaysUp run my Batch File?<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>While the useful NET.EXE utility is great for starting an stopping windows services, it cannot do much beyond that. Enter Microsoft&#8217;s SC.EXE &#8211; a versatile command-line utility built into Windows that can help you start, stop, restart or configure any &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/essential-tools-windows-services-sc-exe\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2261,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[77,139,196],"class_list":["post-513","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-windows-services","tag-essential-tools","tag-sc-exe","tag-windows-services-2"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=513"}],"version-history":[{"count":0,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/513\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/2261"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}