{"id":61,"date":"2006-07-16T22:17:13","date_gmt":"2006-07-16T20:17:13","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=61"},"modified":"2006-12-28T22:08:04","modified_gmt":"2006-12-28T20:08:04","slug":"starta-om-en-tjanst","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=61","title":{"rendered":"Restart a service"},"content":{"rendered":"<p class=\"MsoNormal\" style=\"margin: 0cm 0cm 10pt\"><font face=\"Calibri\" size=\"3\">Here is a script that will monitor a service. If the service is &#8220;stopped&#8221; it will be restarted and a event will be generated in the local event viewer. You can create a rule to collect event ID 4 and\/or event source WSH, then you will get information about it in Operators Console. <\/font><\/p>\n<p><code><br \/>\nstrServiceName = \"Alerter\"<\/code><code>strComputer = \".\"<br \/>\nSet objWMIService = GetObject(\"winmgmts:\" _<br \/>\n& \"{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\cimv2\")<br \/>\nSet colListOfServices = objWMIService.ExecQuery _<br \/>\n(\"Select * from Win32_Service Where Name = '\" & strServiceName & \"'\")<br \/>\nFor Each objService in colListOfServices<br \/>\nIf objService.State = \"Stopped\" Then<br \/>\nobjService.StartService()<\/code><code>Const EVEN_INFORMATION = 4<br \/>\nSet objShell = CreateObject(\"Wscript.Shell\")<br \/>\nobjShell.LogEvent 4, strServiceName & \" has been restarted.\"<\/p>\n<p>End If<br \/>\nNext<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a script that will monitor a service. If the service is &#8220;stopped&#8221; it will be restarted and a event will be generated in the local event viewer. You can create a rule to collect event ID 4 and\/or event source WSH, then you will get information about it in Operators Console. strServiceName = &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=61\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[13],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/61"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=61"}],"version-history":[{"count":0,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/61\/revisions"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}