{"id":52643,"date":"2009-08-24T03:01:00","date_gmt":"2009-08-24T03:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/08\/24\/hey-scripting-guy-can-i-list-the-program-identifiers-that-are-on-my-computer\/"},"modified":"2009-08-24T03:01:00","modified_gmt":"2009-08-24T03:01:00","slug":"hey-scripting-guy-can-i-list-the-program-identifiers-that-are-on-my-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-i-list-the-program-identifiers-that-are-on-my-computer\/","title":{"rendered":"Hey, Scripting Guy! Can I List the Program Identifiers That Are on My Computer?"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p class=\"MsoNormal\"><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 class=\"MsoNormal\">Hey, Scripting Guy! I am looking for a script that will list program identifiers on my computer. Have one of those?<\/p>\n<\/p>\n<p class=\"MsoNormal\">&#8212; CG<\/p>\n<p class=\"MsoNormal\">\n<p><span><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\"><\/span><\/p>\n<\/p>\n<p class=\"MsoNormal\">Hello CG, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. It is interesting you ask for a script that will list program identifiers on your computer. Program identifiers (PIDs) are the secret word combinations that are used when creating objects in VBScript. Knowing what PIDs are available and how to use them can open many new scripting doors while working in either VBScript or in Windows PowerShell.<\/p>\n<p class=\"MsoNormal\">When I flew to Sao Paulo, Brazil, a few years ago to teach a VBScript class at our Microsoft Office (I fell in love with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Feijoada\"><font face=\"Segoe\">feijoada<\/font><\/a> while I was there), I wrote a really cool script while on the plane. This script trolled the registry (HKEY_CLASSES_ROOT) to look for PIDs. When a PID was found, the script would call <b>CreateObject<\/b> and pass the PID to it. The script would then look for errors. If no error was generated, the PID was written to a text file. Because I was calling <b>CreateObject<\/b>, you might have guessed that I wrote the script in VBScript. <\/p>\n<p class=\"MsoNormal\">As luck would have it, the first day I was in Sao Paulo, I was asked by one of my students about masking a password for a script. I went back to the hotel room, and searched the Internet, but was unable to find anything. On a lark, I searched my text file of PIDs for an object that might have something to do with scripts and passwords. I found a COM object named <b>scriptpw.password<\/b>. With a name like that, it is bound to have something to do with passwords and scripts. As a matter of fact, it does have something to do with masking passwords. We even have a Hey, Scripting Guy! article that talks about this: <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2005\/02\/04\/how-can-i-mask-passwords-using-an-inputbox.aspx\"><font face=\"Segoe\">How Can I Mask Passwords Using an Input Box?<\/font><\/a> Back then, there was no documentation for the <b>scriptpw.password<\/b> object (and certainly no Hey, Scripting Guy! article), so how did I figure out if I could use the object, and more importantly, <i>how<\/i> to use it? I opened the COM object in an object browser. Object browsers allow you to look at objects in a graphical fashion. Many programming environments have object browsers, and you can even download them from the Internet. If you have installed the Windows software development kit (SDK) to your computer, you will have an object browser available to you, as seen here:<\/p>\n<p class=\"Fig-Graphic\"><span><\/span><\/p>\n<p class=\"Num-Caption\"><span><span><font face=\"Arial\"><img decoding=\"async\" title=\"Image of object browser in Windows SDK\" alt=\"Image of object browser in Windows SDK\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/august\/hey0824\/hsg-8-24-09-01.jpg\" width=\"600\" height=\"264\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/august\/hey0821\/hsg-8-21-09-01.jpg\"><\/a><\/font><\/span><\/span><\/p>\n<p class=\"MsoNormal\">As you can see, the <b>scriptpw.password<\/b> class contains a single method that is called <b>Get-Password<\/b>. The method takes no arguments and returns a string. Armed with that information, I was able to write the script the student required.<span>&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\">(The <b>scriptpw.password<\/b> object is no longer available beginning with Windows Vista. However, Windows PowerShell includes the <b>Get-Credential<\/b> and the <b>Read-Host<\/b> cmdlets that can be used instead.)<\/p>\n<p class=\"MsoNormal\">A <a href=\"http:\/\/gallery.technet.microsoft.com\/ScriptCenter\/en-us\/02d55abb-2d61-4e2c-bca1-a1359c5386f3\"><font face=\"Segoe\">VBScript that will list PIDs<\/font><\/a> is seen here. I found it by searching for &ldquo;Program ID&rdquo; in the new <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/en-us\/\">TechNet Script Center Gallery<\/a>. <span>&nbsp;<\/span><\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>ListProgIDs.vbs<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><span><font><font face=\"Lucida Sans Typewriter\">On Error Resume Next<\/p>\n<p>strComputer = &#8220;.&#8221;<br>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; _<br><span>&nbsp;&nbsp;&nbsp; <\/span>&amp; &#8220;{impersonationLevel=impersonate}!\\&#8221; &amp; strComputer &amp; &#8220;rootcimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery _<br><span>&nbsp;&nbsp;&nbsp; <\/span>(&#8220;Select * from Win32_ProgIDSpecification&#8221;)<\/p>\n<p>For Each objItem in colItems<br><span>&nbsp;&nbsp;&nbsp; <\/span>Wscript.Echo &#8220;Caption: &#8221; &amp; objItem.Caption<br><span>&nbsp;&nbsp;&nbsp; <\/span>Wscript.Echo &#8220;Check ID: &#8221; &amp; objItem.CheckID<br><span>&nbsp;&nbsp;&nbsp; <\/span>Wscript.Echo &#8220;Name: &#8221; &amp; objItem.Name<br><span>&nbsp;&nbsp;&nbsp; <\/span>Wscript.Echo &#8220;Parent: &#8221; &amp; objItem.Parent<br><span>&nbsp;&nbsp;&nbsp; <\/span>Wscript.Echo &#8220;ProgID: &#8221; &amp; objItem.ProgID<br>Next<\/p>\n<p><br><\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The ListProgIDs.vbs script uses the <b>Win32_ProgIDSpecification<\/b> WMI class. To query the WMI class, the <b>ExecQuery<\/b> method is used from the WMI service object. The WMI query returns a collection of information that is stored in the <b>colItems<\/b> variable. The <b>For Each Next<\/b> statement is used to walk through the collection, and <b>Wscript.Echo<\/b> prints out each property. <\/p>\n<p class=\"MsoNormal\">In the ListProgIds.ps1 script that follows this paragraph, the <b>Get-WmiObject<\/b> cmdlet is used to query the <b>Win32_ProgIDSpecification<\/b> WMI class. Instead of storing the results in a variable, the results are pipelined to the <b>Format-Table<\/b> cmdlet. There is much redundancy between the properties of the <b>Win32_ProgIDSpecification<\/b> WMI class. Therefore, a better display of information can be made by creating a table and displaying the <b>progID<\/b> property and the <b>description<\/b> property. The <b>autosize<\/b> property will size the table to avoid wasting space. The <b>more<\/b> function is used to display one page of information at a time. The complete ListProgIDs.ps1 script is seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>ListProgIDs.ps1<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><span><font><font face=\"Lucida Sans Typewriter\">Get-WmiObject -Class Win32_ProgIDSpecification | <\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"CodeBlockScreened\"><span><font><font face=\"Lucida Sans Typewriter\">Format-Table &ndash;Property ProgID, description -AutoSize | more<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The same display information that is returned by the ListProgIDs.vbs script could be obtained by not using the formatting cmdlets. The command could be written by using the <b>gwmi<\/b> alias (instead of the full <b>Get-WmiObject<\/b>). The revised command is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Gwmi win32_ProgIDSpecification<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The ListProgIDs.ps1 script produces the output seen here: <\/p>\n<p class=\"Fig-Graphic\"><span><\/span><\/p>\n<p class=\"MsoNormal\">\n<p><img decoding=\"async\" title=\"Image of ListProgIDs.ps1 output\" alt=\"Image of ListProgIDs.ps1 output\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/august\/hey0824\/hsg-8-24-09-02.jpg\" width=\"600\" height=\"502\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/august\/hey0824\/hsg-8-24-09-01.jpg\"><\/a><\/p>\n<\/p>\n<p class=\"Num-Caption\">\n<p class=\"MsoNormal\">To explore the objects and find out what an object can do, you can use the <b>New-Object<\/b> cmdlet with the <b>comobject<\/b> parameter. This will create an instance of the object. You will want to use a variable to hold the object. This is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$access = New-Object &ndash;comobject Access.Application<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">With Windows PowerShell, you do not need to download and install an object browser, because you can use the <b>Get-Member<\/b> cmdlet to display the methods and the properties of the object. The syntax for the command is seen here: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$access | Get-Member<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">When you run the above command, the results seen here are displayed: <\/p>\n<p class=\"Fig-Graphic\"><span><\/span><\/p>\n<p class=\"Num-Caption\"><span><span><img decoding=\"async\" title=\"Image of results of running Get-Member cmdlet\" alt=\"Image of results of running Get-Member cmdlet\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/august\/hey0824\/hsg-8-24-09-03.jpg\" width=\"600\" height=\"511\"><\/span><\/span><\/p>\n<p class=\"MsoNormal\">Well, CG, that is all there is to listing PIDs. You can use a WMI class to list the PIDs. After you find a PID, you can look it up on MSDN or on the Script Center. You can also use the <b>New-Object<\/b> cmdlet to create an instance of the object and pass it to the <b>Get-Member<\/b> cmdlet. Keep in mind that all objects are not designed to be worked with directly. <\/p>\n<p class=\"MsoNormal\">Join us tomorrow as we continue exploring Script Center Gallery scripts. If you want to keep up to date on activities on the Script Center, follow us on <a href=\"https:\/\/twitter.com\/scriptingguys\/\">Twitter<\/a> or <a href=\"http:\/\/www.facebook.com\/group.php?gid=5901799452\">Facebook<\/a>. If you have questions, you can post them on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a>, or send e-mail to <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a>. Until tomorrow, have a great day!<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/p>\n<p><\/span><\/b><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! I am looking for a script that will list program identifiers on my computer. Have one of those? &#8212; CG Hello CG, Microsoft Scripting Guy Ed Wilson here. It is interesting you ask for a script that will list program identifiers on your computer. Program identifiers (PIDs) are the secret word [&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":[739,31,3,5,45,6],"class_list":["post-52643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-com-and-dcom","tag-operating-system","tag-scripting-guy","tag-vbscript","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! I am looking for a script that will list program identifiers on my computer. Have one of those? &#8212; CG Hello CG, Microsoft Scripting Guy Ed Wilson here. It is interesting you ask for a script that will list program identifiers on your computer. Program identifiers (PIDs) are the secret word [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52643","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=52643"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52643\/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=52643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=52643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=52643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}