{"id":71463,"date":"2004-09-10T20:25:00","date_gmt":"2004-09-10T20:25:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/09\/10\/how-can-i-tell-which-account-a-service-is-running-under\/"},"modified":"2004-09-10T20:25:00","modified_gmt":"2004-09-10T20:25:00","slug":"how-can-i-tell-which-account-a-service-is-running-under","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-tell-which-account-a-service-is-running-under\/","title":{"rendered":"How Can I Tell Which Account a Service is Running Under?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p>We have services that run under a particular user account. Each time we change the password for that user account, we need to change the password for any services that run under that account as well. But how can we tell which account a service is running under?<\/p>\n<p>&#8212; SA<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/a><\/p>\n<p>Hey, SA. By and large WMI is a pretty transparent technology. To manage services, you use a class named Win32_Service. To manage processes, you use a class named Win32_Process. Not exactly rocket science, right?<\/p>\n<p>Of course, every now and then WMI throws you a curve, and the service account name happens to be one of those instances. It\u2019s actually easy to determine the account name under which a service runs, provided you know that this information is found using the <i>StartName<\/i> property:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject _\n    (\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\nSet colServices = objWMIService.ExecQuery _\n    (\"Select * From Win32_Service\")\nFor Each objService in colServices\n    Wscript.Echo objService.Name, objService.StartName\nNext\n<\/pre>\n<p>The preceding code shows you the name and account name for each service installed on a computer. If you only want a list of services running under a specific account (e.g., KenMyer), then use code similar to this:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject _\n    (\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\nSet colServices = objWMIService.ExecQuery _\n    (\"Select * From Win32_Service Where StartName = 'KenMyer'\")\nFor Each objService in colServices\n    Wscript.Echo objService.Name\nNext\n<\/pre>\n<p>And then how do you change the password using a script? Why, by using a script like this one:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject _\n    (\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\nSet colServices = objWMIService.ExecQuery _\n    (\"Select * From Win32_Service Where StartName = 'KenMyer'\")\nFor Each objService in colServices\n    errReturn = objService.Change( , , , , , , , \"fgT54ghde*&amp;\")\nNext\n<\/pre>\n<p>Note that when using the Change method, the password is the <i>eighth<\/i> parameter passed. That means you must preface the new password (&#8220;fgT54ghde*&amp;&#8221;) with seven commas. A bit odd, but it works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have services that run under a particular user account. Each time we change the password for that user account, we need to change the password for any services that run under that account as well. But how can we tell which account a service is running under? &#8212; SA Hey, SA. By and large [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,3,4,39,5,6],"class_list":["post-71463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-scripting-guy","tag-scripting-techniques","tag-services","tag-vbscript","tag-wmi"],"acf":[],"blog_post_summary":"<p>We have services that run under a particular user account. Each time we change the password for that user account, we need to change the password for any services that run under that account as well. But how can we tell which account a service is running under? &#8212; SA Hey, SA. By and large [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=71463"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71463\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=71463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}