{"id":6134,"date":"2014-04-01T13:59:00","date_gmt":"2014-04-01T13:59:00","guid":{"rendered":""},"modified":"2026-04-18T22:43:19","modified_gmt":"2026-04-18T22:43:19","slug":"how-to-get-uptime-for-a-windows-service","status":"publish","type":"post","link":"https:\/\/hellem.org\/wblog\/?p=6134","title":{"rendered":"How to get uptime for a Windows service"},"content":{"rendered":"<p>Needed to know the uptime of a service on a Windows 2012 server to verify that the suggested solution for restarting all Splunk Universial Forwarders did work, see <a href=\"http:\/\/answers.splunk.com\/answers\/129614\/how-can-i-restart-all-my-forwarders\">answers.splunk.com\/..\/how-can-i-restart-all-my-forwarders<\/a>.<\/p>\n<p>Solution found here <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2007\/02\/28\/how-can-i-get-the-uptime-of-a-service.aspx\">\/blogs.technet.com\/&#8230;\/how-can-i-get-the-uptime-of-a-service<\/a>, did make some minor adjustments to the vbscript as shown below.<\/p>\n<p><!-- codeblock lang=vbscript line=1 --><\/p>\n<pre class=\"codeblock\"><code>strComputer = \".\"\r\n\r\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\r\n\r\nSet colServices = objWMIService.ExecQuery _\r\n    (\"Select * From Win32_Service WHERE displayname = 'SplunkForwarder'\")\r\n \r\nFor Each objService in colServices\r\n\r\n    intProcessID = objService.ProcessID\r\n\r\n    Set colProcesses = objWMIService.ExecQuery _\r\n        (\"Select * From Win32_Process Where ProcessID = \" &amp; intProcessID)\r\n\r\n    For Each objProcess in colProcesses\r\n        Wscript.Echo objService.Name + \"\/\" + objProcess.Name + \" \" + objProcess.CreationDate\r\n    Next\r\nNext<\/code><\/pre>\n<p><!-- \/codeblock --><\/p>\n<p>Running it from the Powershell prompt like this <code class=\"codespan\">PS D:\\Temp> cscript.exe .\\uptime.vbs<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Needed to know the uptime of a service on a Windows 2012 server to verify that the suggested solution for restarting all Splunk Universial Forwarders did work, see answers.splunk.com\/..\/how-can-i-restart-all-my-forwarders. Solution found here \/blogs.technet.com\/&#8230;\/how-can-i-get-the-uptime-of-a-service, did make some minor adjustments to the vbscript as shown below. strComputer = &#8220;.&#8221; Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"class_list":["post-6134","post","type-post","status-publish","format-standard","hentry","category-work-geek"],"_links":{"self":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/6134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6134"}],"version-history":[{"count":1,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/6134\/revisions"}],"predecessor-version":[{"id":11492,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/6134\/revisions\/11492"}],"wp:attachment":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}