{"id":37,"date":"2017-06-18T12:58:00","date_gmt":"2017-06-18T16:58:00","guid":{"rendered":"http:\/\/ziviz.us\/WP\/?p=37"},"modified":"2017-06-18T13:02:10","modified_gmt":"2017-06-18T17:02:10","slug":"installing-a-custom-service","status":"publish","type":"post","link":"https:\/\/www.ziviz.net\/WP\/2017\/06\/18\/installing-a-custom-service\/","title":{"rendered":"Installing a Custom Service"},"content":{"rendered":"<p style=\"text-align: center;\"><em>This post was migrated from my older blog.<\/em><\/p>\n<p>So I was playing around with custom services in C# a couple years back. I never created a service before so I was going off of Microsoft&#8217;s MSDN articles and a few blogs that Google searches turned up. They all followed the same pattern.<\/p>\n<ul>\n<li>Create a new application that inherits <a class=\"external text\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.serviceprocess.servicebase%28v=vs.110%29.aspx\" rel=\"nofollow\">ServiceBase<\/a><\/li>\n<li>Create a class that inherits <a class=\"external text\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.configuration.install.installer%28v=vs.110%29.aspx\" rel=\"nofollow\">Installer<\/a><\/li>\n<li>Install the application using <a class=\"external text\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/50614e95%28v=vs.110%29.aspx\" rel=\"nofollow\">InstallUtil.exe<\/a><\/li>\n<\/ul>\n<p>This solution works fine, but I don&#8217;t really like it much.<\/p>\n<p>Fast forward to about a month ago. We had some issues with one of our servers. One of the steps in troubleshooting the issue was to manually check what the machine and resources looked like from Local System&#8217;s perspective. To do this, I opened an instance of <code>cmd.exe<\/code> under the Local System account interactively using the built-in tool <code>SC<\/code>. (More on how to do that <a class=\"external text\" href=\"http:\/\/blogs.msdn.com\/b\/adioltean\/archive\/2004\/11\/27\/271063.aspx\" rel=\"nofollow\">here<\/a>) I did not know about that tool until then. Turns out, all it does is register the application specified, <code>cmd.exe<\/code> in this case, as a service. I decided to test it for use in installing a custom service created in C#. I created a quick service that answered a single incoming TCP connection with &#8220;Hello World&#8221;. Installed it with <code>SC<\/code>, and it worked! I did not have to create an install class within the service, nor did it rely on <code>InstallUtil.exe<\/code>. For more information on <code>SC<\/code> for installing services, check out the <a class=\"external text\" href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc990289.aspx\" rel=\"nofollow\">&#8220;SC Create&#8221; TechNet article<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post was migrated from my older blog. So I was playing around with custom services in C# a couple years back. I never created a service before so I was going off of Microsoft&#8217;s MSDN articles and a few blogs that Google searches turned up. They all followed the same pattern. Create a new &hellip; <a href=\"https:\/\/www.ziviz.net\/WP\/2017\/06\/18\/installing-a-custom-service\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Installing a Custom Service&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-c-sharp","category-sysadmin"],"_links":{"self":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":1,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":38,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/37\/revisions\/38"}],"wp:attachment":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}