{"id":71283,"date":"2004-10-06T13:47:00","date_gmt":"2004-10-06T13:47:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/10\/06\/how-can-i-tell-which-scripts-are-running-on-a-computer\/"},"modified":"2004-10-06T13:47:00","modified_gmt":"2004-10-06T13:47:00","slug":"how-can-i-tell-which-scripts-are-running-on-a-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-tell-which-scripts-are-running-on-a-computer\/","title":{"rendered":"How Can I Tell Which Scripts are Running on a Computer?"},"content":{"rendered":"<p><IMG 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\"> \n<P>Hey, Scripting Guy! How can I tell which scripts are running on a computer?<BR><BR>&#8212; NW<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG 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 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> \n<P>Hey, NW. This is a question we\u2019re always a little reluctant to answer, because there\u2019s a 50-50 chance you\u2019ll be disappointed with what you hear. If you are running Windows 2000 (or a previous version of Windows), the answer is pretty straightforward: you can\u2019t. A script such as this one &#8211; which looks for all processes running under Cscript.exe or Wscript.exe &#8211; can tell that scripts <I>are<\/I> running on a computer:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objWMIService = GetObject(&#8220;winmgmts:&#8221; _\n    &amp; &#8220;{impersonationLevel=impersonate}!\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)\nSet colItems = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Process Where Name = &#8216;cscript.exe'&#8221; &amp; _\n        &#8221; OR Name = &#8216;wscript.exe'&#8221;)\nFor Each objItem in colItems\n    Wscript.Echo objItem.Name\nNext\n<\/PRE>\n<P>However, this script can\u2019t tell you the names of those scripts. In fact, as far as we know, nothing built into the operating system can identify the individual scripts running on a Windows 2000 computer; even Task Manager reports only the process names (Cscript.exe and Wscript.exe).<\/P>\n<P>If you\u2019re running Windows XP or Windows Server 2003, however, then we have a different &#8211; and better &#8211; answer for you. With Windows XP a new property &#8211; CommandLine &#8211; was added to the Win32_Process class. As the name implies, CommandLine tells you the actual command used to start a process. For example, suppose you started a script by typing <B>cscript my_script.vbs<\/B> at the command prompt. The CommandLine property for that script will be this:<\/P><PRE class=\"codeSample\">cscript my_script.vbs\n<\/PRE>\n<P>In other words, now you know that script named My_Script.vbs is running on this machine.<\/P>\n<P>But what if you don\u2019t use the command prompt to start a script, what if you double-click the file icon in Windows Explorer and run the script under Wscript? No problem. Say you double-click the file C:\\Scripts\\My_Script.vbs; you\u2019ll get back a CommandLine value like this:<\/P><PRE class=\"codeSample\">C:\\WINDOWS\\System32\\WScript.exe &#8220;C:\\Scripts\\My_Script.vbs&#8221;\n<\/PRE>\n<P>As you can see, we get the path to the Wscript executable file along with the path to the script that\u2019s actually running. Now that\u2019s more like it, huh?<\/P>\n<P>At any rate, if you\u2019re running Windows XP or Windows Server 2003, here\u2019s a script that will do the trick for you:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objWMIService = GetObject(&#8220;winmgmts:&#8221; _\n    &amp; &#8220;{impersonationLevel=impersonate}!\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)\nSet colItems = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Process Where Name = &#8216;cscript.exe'&#8221; &amp; _\n        &#8221; OR Name = &#8216;wscript.exe'&#8221;)\nFor Each objItem in colItems\n    Wscript.Echo objItem.CommandLine\nNext\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I tell which scripts are running on a computer?&#8212; NW Hey, NW. This is a question we\u2019re always a little reluctant to answer, because there\u2019s a 50-50 chance you\u2019ll be disappointed with what you hear. If you are running Windows 2000 (or a previous version of Windows), the answer is [&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,87,3,5],"class_list":["post-71283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-processes","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I tell which scripts are running on a computer?&#8212; NW Hey, NW. This is a question we\u2019re always a little reluctant to answer, because there\u2019s a 50-50 chance you\u2019ll be disappointed with what you hear. If you are running Windows 2000 (or a previous version of Windows), the answer is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71283","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=71283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71283\/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=71283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}