{"id":46,"date":"2006-06-18T15:00:31","date_gmt":"2006-06-18T13:00:31","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=46"},"modified":"2006-12-28T16:37:24","modified_gmt":"2006-12-28T14:37:24","slug":"starta-om-en-process","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=46","title":{"rendered":"Restart a  process"},"content":{"rendered":"<p>This is a script that will monitor if a process is running more that once, if it is this script will\u00c2\u00a0kill them and restart it.\u00c2\u00a0\u00c2\u00a0This example check if notepad.exe is running more than twice.<\/p>\n<p><code>strComputer = \".\"<br \/>\nSet objWMIService = GetObject(\"winmgmts:\" _<br \/>\n& \"{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\cimv2\")<br \/>\nSet colProcesses = objWMIService.ExecQuery _<br \/>\n(\"Select * from Win32_Process Where Name = 'notepad.exe'\")<br \/>\n'mineapp = \"notepad.exe\"<br \/>\nIf colProcesses.Count => 2 Then<br \/>\n' Wscript.Echo mineapp & \" is running 2 or more instances\"<br \/>\nSet colProcessList = objWMIService.ExecQuery _<br \/>\n(\"Select * from Win32_Process Where Name = 'notepad.exe'\")<\/code><code>For Each objProcess in colProcessList<br \/>\nobjProcess.Terminate()<br \/>\nNext<\/p>\n<p>Set objShell = CreateObject(\"WScript.Shell\")<br \/>\nobjShell.Run \"notepad.exe\"<\/p>\n<p>Else<br \/>\n' Wscript.Echo mineapp & \" is running less than 2 instances\"<br \/>\nEnd If<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a script that will monitor if a process is running more that once, if it is this script will\u00c2\u00a0kill them and restart it.\u00c2\u00a0\u00c2\u00a0This example check if notepad.exe is running more than twice. strComputer = &#8220;.&#8221; Set objWMIService = GetObject(&#8220;winmgmts:&#8221; _ &#038; &#8220;{impersonationLevel=impersonate}!\\\\&#8221; &#038; strComputer &#038; &#8220;\\root\\cimv2&#8221;) Set colProcesses = objWMIService.ExecQuery _ (&#8220;Select * &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=46\">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,"footnotes":""},"categories":[2,13],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-microsoft-operations-manager-2005","category-scripts"],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=46"}],"version-history":[{"count":0,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}