{"id":720,"date":"2013-03-02T15:00:02","date_gmt":"2013-03-02T19:00:02","guid":{"rendered":"http:\/\/blog.bitsofgenius.com\/?p=720"},"modified":"2013-03-02T15:00:02","modified_gmt":"2013-03-02T19:00:02","slug":"install-or-uninstall-a-windows-service-without-installation-packages","status":"publish","type":"post","link":"https:\/\/blog.bitsofgenius.com\/?p=720","title":{"rendered":"Install or Uninstall a Windows Service without Installation Packages"},"content":{"rendered":"<p>Generally windows services are deployed one of two ways. \u00a0One way is in an installation package, that will handle the installation for a user. \u00a0The service may be one of several parts of an installation package, and the package approach makes the installation easier to maintain. \u00a0This method is mostly useful for an unknown number of installation points (i.e. machines), and mandatory when the installation is for an end user on their personal device.<\/p>\n<p>The second way which I focus on here, is by using the InstallUtil.exe utility in the .NET Framework. \u00a0This console application has a few handy uses:<\/p>\n<ul>\n<li>bulk deployment of a single, simple service across a number of servers in a given cluster or data center.<\/li>\n<li>scripting the install\/uninstall as an option into the Windows Explorer context menu for executable files.<\/li>\n<\/ul>\n<p>I&#8217;ve rediscovered two files I have been using for a while, which can facilitate this specific interface to the context menu in Windows Explorer. \u00a0The first is a command file which can be executed directly, but is designed to be called from a Windows explorer context menu. It currently supports version 2.0 or 4.0 of the utility, but can be easily adjusted as new versions of InstallUtil debut in later frameworks.<\/p>\n<p>The second is the registry file to merge into the HKEY_CLASSES_ROOT to create the Windows Explorer context menu for the install\/uninstall options. Simply create a folder C:\\Scripts\\ExplorerContext, copy these two files into it, merge the registry settings file, and then you&#8217;ll see four new options on an executable file for installing or uninstalling the service in .NET version 2.0 or 4.0<\/p>\n<p>The process to install these files is to place these files in a folder, and merge the registry file. \u00a0Be sure to adjust the paths in the Registry file content to the correct path to the command file, if it is note the default: \u00a0C:\\Script\\ExplorerContent<\/p>\n<p>To use the file from Explorer Context, copy the service executable and support files to their operating folder. \u00a0From Windows Explorer, right click on the entry executable for the service, and select the Service Install menu option for the version on .NET needed.<\/p>\n<p>Likewise, to uninstall the service, select one of the uninstall options.<\/p>\n<p>That&#8217;s it. \u00a0The command file is below. \u00a0You can download both the command file and the registry file as a zip file <a href=\"\/CodeSource\/install_services_dotNET.zip\">here<\/a>. \u00a0This is a very useful was of automating installs for bulk code updates.<\/p>\n<pre lang=\"DOS\" line=\"0\" escaped=\"true\">@echo off\r\n\r\nREM install_services_dotNET.cmd -- use the dotNET InstallUtil.exe console app to install\/uninstall\r\nREM a windows service.\r\nREM J. Schultz -- 3\/11\/2010\r\n\r\nREM Interface to Windows explorer as a context menu item set using the following registry settings\r\nREM NOTE: Adjust the path to the cmd file as needed (C:\\\\Scripts\\\\ExplorerContext\\\\).\r\n\r\nREM ------------------------------------- 8&lt; --------------------------------------\r\nREM Windows Registry Editor Version 5.00\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell]\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 2.0 Service Install]\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 2.0 Service Install\\command]\r\nREM @=\"C:\\\\Scripts\\\\ExplorerContext\\\\install_services_dotNET.cmd I 2.0 \\\"%1\\\"\"\r\nREM\r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 2.0 Service Uninstall]\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 2.0 Service Uninstall\\command]\r\nREM @=\"C:\\\\Scripts\\\\ExplorerContext\\\\install_services_dotNET.cmd U 2.0 \\\"%1\\\"\"\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 4.0 Service Install]\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 4.0 Service Install\\command]\r\nREM @=\"C:\\\\Scripts\\\\ExplorerContext\\\\install_services_dotNET.cmd I 4.0 \\\"%1\\\"\"\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 4.0 Service Uninstall]\r\nREM \r\nREM [HKEY_CLASSES_ROOT\\exefile\\shell\\.NET 4.0 Service Uninstall\\command]\r\nREM \r\nREM @=\"C:\\\\Scripts\\\\ExplorerContext\\\\install_services_dotNET.cmd U 4.0 \\\"%1\\\"\"\r\nREM\r\nREM ------------------------------------- 8&lt; --------------------------------------\r\n\r\nif \/I \"%1\" == \"I\" goto CONT01 \r\nif \/I \"%1\" == \"U\" goto CONT01 \r\necho First parameter must I for install, or U for uninstall. \r\ngoto HELP \r\n\r\n:CONT01 \r\nif \"%2\" NEQ \"\" if \/I \"%2\" == \"2.0\" goto CONT02 \r\nif \"%2\" NEQ \"\" if \/I \"%2\" == \"4.0\" goto CONT02 \r\necho Second parameter must specify the dotNET version: 2.0 or 4.0 \r\ngoto HELP \r\n\r\n:CONT02 \r\nif \"%3\" NEQ \"\" goto CONT03 \r\necho Third parameter must specify the full path to the executable file for the service.\r\ngoto HELP \r\n\r\n:CONT03 \r\nif exist %3 goto CONT04 \r\necho The executable file for the service (third parameter) specifies a non-existent file. \r\ngoto HELP \r\n\r\n:CONT04 \r\nif \"%4\" EQU \"\" goto CONT05 \r\necho Expected three parameters, but have four or more. \r\ngoto HELP \r\n\r\n:CONT05 \r\nREM Parameter check passed \r\nREM %~d3 \r\nREM cd \"%~p3\" \r\n\r\nif \/I \"%1\" == \"I\" echo This will attempt to ** INSTALL ** the file... \r\nif \/I \"%1\" == \"U\" echo This will attempt to ** REMOVE ** the file... \r\necho. \r\necho %3 \r\necho. \r\necho .. as a service.  Press ENTER to continue, or Ctrl+Break to abort. pause &gt; nul\r\necho.\r\n\r\nif \/I \"%1\" == \"I\" if \/I \"%2\" == \"2.0\" \"%windir%\\microsoft.net\\framework\\v2.0.50727\\installutil.exe\" %3\r\n\r\nif \/I \"%1\" == \"U\" if \/I \"%2\" == \"2.0\" \"%windir%\\microsoft.net\\framework\\v2.0.50727\\installutil.exe\" \/u %3\r\n\r\nif \/I \"%1\" == \"I\" if \/I \"%2\" == \"4.0\" \"%windir%\\Microsoft.NET\\Framework\\v4.0.30319\\installutil.exe\" %3\r\n\r\nif \/I \"%1\" == \"U\" if \/I \"%2\" == \"4.0\" \"%windir%\\Microsoft.NET\\Framework\\v4.0.30319\\installutil.exe\" \/u %3\r\n\r\necho.\r\ngoto END\r\n\r\n:HELP\r\necho.\r\necho Example command lines:\r\necho.\r\necho    install_services_dotNET.cmd I 2.0 \"C:\\Program Files\\My Company\\My Service\\ServiceApp.exe\"\r\necho    install_services_dotNET.cmd U 2.0 \"C:\\Program Files\\My Company\\My Service\\ServiceApp.exe\"\r\necho.\r\necho    install_services_dotNET.cmd I 2.0 \"C:\\Program Files\\My Company\\My Service\\ServiceApp.exe\"\r\necho    install_services_dotNET.cmd U 2.0 \"C:\\Program Files\\My Company\\My Service\\ServiceApp.exe\"\r\necho.\r\n\r\n:END\r\necho Press any key to close this window.\r\npause &gt; nul<\/pre>\n<p>The two files below demonstrate what is needed for windows context. \u00a0One is a batch file<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Generally windows services are deployed one of two ways. \u00a0One way is in an installation package, that will handle the installation for a user. \u00a0The service may be one of several parts of an installation package, and the package approach makes the installation easier to maintain. \u00a0This method is mostly useful for an unknown number [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,29,20,17],"tags":[],"class_list":["post-720","post","type-post","status-publish","format-standard","hentry","category-dotnettechniques","category-small-utilities","category-technologynetworking","category-tips-and-tricks"],"_links":{"self":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=720"}],"version-history":[{"count":18,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/720\/revisions"}],"predecessor-version":[{"id":777,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/720\/revisions\/777"}],"wp:attachment":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}