{"id":1263,"date":"2011-01-02T09:59:54","date_gmt":"2011-01-02T09:59:54","guid":{"rendered":"https:\/\/www.buarotti.ch\/?p=1263"},"modified":"2012-01-21T10:05:47","modified_gmt":"2012-01-21T10:05:47","slug":"service-inkl-abhangigkeits-services-neu-starten","status":"publish","type":"post","link":"https:\/\/www.buarotti.ch\/?p=1263","title":{"rendered":"Service inkl. Abh\u00e4ngigkeits Services neu starten"},"content":{"rendered":"<p>Hier ein Script welches Services inkl. deren abh\u00e4ngigkeiten neu startet.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n\r\n'***********************************************************************************************\r\n ' This program is Copyright (c) 2001 Microsoft Corporation.\r\n '\r\n ' All rights reserved.\r\n '\r\n ' THIS CODE AND INFORMATION IS PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF\r\n ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\r\n ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\/OR FITNESS FOR A\r\n ' PARTICULAR PURPOSE.\r\n '\r\n ' IN NO EVENT SHALL MICROSOFT AND\/OR ITS RESPECTIVE SUPPLIERS BE\r\n ' LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY\r\n ' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,\r\n ' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r\n ' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE\r\n ' OF THIS CODE OR INFORMATION.\r\n\r\n ' Services restart script\r\n ' Maintains start \/ stop dependencies regardless of ISA installation type\r\n ' Date - 9\/7\/2001\r\n '***********************************************************************************************\r\n\r\n Option Explicit\r\n\r\n Dim objSWbemLocator, objSWbemServices, objServices, Associator, Rtn, BlnRtn, SvcName\r\n Dim outFile, fs, logfile, objEMail\r\n ' Logfile definitionen...\r\n set fs = createobject(&quot;Scripting.filesystemobject&quot;)\r\n set logfile = fs.opentextfile(&quot;D:\\Service.log&quot;, 8, true,0)\r\n\r\n SvcName = &quot;PlugPlay&quot;\r\n Set objSWbemLocator = CreateObject(&quot;WbemScripting.SWbemLocator&quot;)\r\n Set objSWbemServices = objSWbemLocator.ConnectServer(&quot;&quot;, &quot;root\\CIMV2&quot;,&quot;&quot; ,&quot;&quot;)\r\n Set objServices = objSWbemServices.Get(&quot;Win32_Service.Name=&quot;&quot;&quot; &amp; SvcName &amp; &quot;&quot;&quot;&quot;)\r\n\r\n StopService(objServices)\r\n wscript.echo\r\n StartService(objServices)\r\n\r\n 'logfile.writeline &quot;-- Automatic Service Stop and Start Task will start now &#x5B;&quot; &amp; Date &amp; &quot;-&quot; &amp; Time &amp; &quot;] --&quot;\r\n\r\n Function StopService(objService)\r\n StopDependentServices(objService.Name)\r\n Wscript.Sleep 5000\r\n wscript.echo &quot;Stopping &quot; &amp; objService.Name\r\n Rtn = objService.StopService(objService.Name)\r\n If Rtn = 3 then StopDependentServices(objService.Name)\r\n ' Logfile wird geschrieben\r\n logfile.writeline &quot;&#x5B;&quot; &amp; Date &amp; &quot;-&quot; &amp; Time &amp; &quot;] Service &quot; &amp; objService.Name &amp; &quot; was Stopped&quot;\r\n If Rtn &lt;&gt; 0 then\r\n Wscript.echo CheckReq(Rtn, objService.Name)\r\n Exit Function\r\n End if\r\n Wscript.Sleep 3000\r\n End Function\r\n\r\n Function StartService(objService)\r\n wscript.echo &quot;Starting &quot; &amp; objService.Name\r\n Rtn = objService.StartService(objService.Name)\r\n logfile.writeline &quot;&#x5B;&quot; &amp; Date &amp; &quot;-&quot; &amp; Time &amp; &quot;] Service &quot; &amp; objService.Name &amp; &quot; was Started&quot;\r\n If Rtn &lt;&gt; 0 then\r\n Wscript.echo CheckReq(Rtn, objService.Name)\r\n End if\r\n Wscript.Sleep 5000\r\n StartDependentServices(objService.Name)\r\n End Function\r\n\r\n Function StopDependentServices(strServiceName)\r\n logfile.writeline &quot;&#x5B;&quot; &amp; Date &amp; &quot;-&quot; &amp; Time &amp; &quot;] -!- Automatic Service Stop and Start Task will start now&quot;\r\n For Each Associator In objSWbemServices.AssociatorsOf(&quot;Win32_Service.Name=&quot;&quot;&quot; &amp; strServiceName &amp; &quot;&quot;&quot;&quot;, &quot;Win32_DependentService&quot;,, &quot;Dependent&quot;)\r\n If (Associator.StartMode = &quot;Auto&quot;) and (Associator.State = &quot;Running&quot;) then\r\n wscript.echo &quot;Stopping dependent service: &quot; &amp; Associator.Name\r\n Rtn = Associator.StopService\r\n If Rtn = 3 then StopDependentServices(Associator.Name)\r\n logfile.writeline &quot;&#x5B;&quot; &amp; Date &amp; &quot;-&quot; &amp; Time &amp; &quot;] Dependent Service &quot; &amp; Associator.Name &amp; &quot; was Stopped&quot;\r\n If Rtn &lt;&gt; 0 Then\r\n Wscript.echo CheckReq(Rtn, Associator.Name)\r\n Exit Function\r\n End If\r\n End If\r\n Next\r\n End Function\r\n\r\n Function StartDependentServices(strServiceName)\r\n For Each Associator In objSWbemServices.AssociatorsOf(&quot;Win32_Service.Name=&quot;&quot;&quot; &amp; strServiceName &amp; &quot;&quot;&quot;&quot;, &quot;Win32_DependentService&quot;,, &quot;Dependent&quot;)\r\n If (Associator.StartMode = &quot;Auto&quot;) and (Associator.State = &quot;Stopped&quot;) then\r\n wscript.echo &quot;Starting dependent service: &quot; &amp; Associator.Name\r\n Rtn = Associator.StartService\r\n logfile.writeline &quot;&#x5B;&quot; &amp; Date &amp; &quot;-&quot; &amp; Time &amp; &quot;] Dependent Service &quot; &amp; Associator.Name &amp; &quot; was Sarted&quot;\r\n If Rtn &lt;&gt; 0 Then\r\n Wscript.echo CheckReq(Rtn, Associator.Name)\r\n Exit Function\r\n End If\r\n End If\r\n Next\r\n End Function\r\n\r\n Function CheckReq(Error, Service)\r\n\r\n Dim objSvc\r\n Select Case Error\r\n Case 0\r\n CheckReq = &quot;The request was accepted.&quot;\r\n Case 1\r\n CheckReq = &quot;The request is not supported.&quot;\r\n Case 2\r\n CheckReq = &quot;The user did not have the necessary access.&quot;\r\n Case 3\r\n CheckReq = &quot;The service cannot be stopped because other services that are running are dependent on it.&quot;\r\n Case 4\r\n CheckReq = &quot;The requested control code is not valid, or it is unacceptable to the service.&quot;\r\n Case 5\r\n Set objSvc = objSWbemServices.Get(&quot;Win32_BaseService.Name=&quot;&quot;&quot; &amp; Service &amp; &quot;&quot;&quot;&quot;)\r\n CheckReq = &quot;The requested control code cannot be sent to the service because the service state is set to '&quot; &amp; objSvc.State &amp; &quot;'&quot;\r\n Case 6\r\n CheckReq = &quot;The service has not been started.&quot;\r\n Case 7\r\n CheckReq = &quot;The service did not respond to the start request in a timely fashion.&quot;\r\n Case 8\r\n CheckReq = &quot;Unknown failure when starting the service.&quot;\r\n Case 9\r\n CheckReq = &quot;The directory path to the service executable file was not found.&quot;\r\n Case 10\r\n CheckReq = &quot;The service is already running.&quot;\r\n Case 11\r\n CheckReq = &quot;The database to add a new service is locked.&quot;\r\n Case 12\r\n CheckReq = &quot;A dependency for which this service relies on has been removed from the system.&quot;\r\n Case 13\r\n CheckReq = &quot;The service failed to find the service needed from a dependent service.&quot;\r\n Case 14\r\n CheckReq = &quot;The service has been disabled from the system.&quot;\r\n Case 15\r\n CheckReq = &quot;The service does not have the correct authentication to run on the system.&quot;\r\n Case 16\r\n CheckReq = &quot;This service is being removed from the system.&quot;\r\n Case 17\r\n CheckReq = &quot;There is no execution thread for the service.&quot;\r\n Case 18\r\n CheckReq = &quot;There are circular dependencies when starting the service.&quot;\r\n Case 19\r\n CheckReq = &quot;There is a service running under the same name.&quot;\r\n Case 20\r\n CheckReq = &quot;There are invalid characters in the name of the service.&quot;\r\n Case 21\r\n CheckReq = &quot;Invalid parameters have been passed to the service.&quot;\r\n Case 22\r\n CheckReq = &quot;The account which this service is to run under is either invalid or lacks the permissions to run the service.&quot;\r\n Case 23\r\n CheckReq = &quot;The service exists in the database of services available from the system.&quot;\r\n Case 24\r\n CheckReq = &quot;The service is currently paused in the system.&quot;\r\n Case Else\r\n CheckReq = &quot;I don't know WTF happened: RTN = &quot; &amp; Cstr(Error)\r\n End Select\r\n\r\n End Function\r\n<\/pre>\n<h3>Related Images:<\/h3>","protected":false},"excerpt":{"rendered":"<p>Hier ein Script welches Services inkl. deren abh\u00e4ngigkeiten neu startet. &#8218;*********************************************************************************************** &#8218; This program is Copyright (c) 2001 Microsoft Corporation. &#8218; &#8218; All rights reserved. &#8218; &#8218; THIS CODE AND INFORMATION IS PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF &#8218; ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO &#8218; THE IMPLIED WARRANTIES OF [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[11],"tags":[66],"class_list":["post-1263","post","type-post","status-publish","format-standard","hentry","category-vbscript","tag-service-vbs"],"_links":{"self":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1263"}],"version-history":[{"count":6,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1263\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1263\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}