{"id":85949,"date":"2004-09-29T05:54:08","date_gmt":"2004-09-29T13:54:08","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=85949"},"modified":"2019-06-05T06:09:00","modified_gmt":"2019-06-05T14:09:00","slug":"how-can-i-tell-which-service-packs-have-been-installed-on-a-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-tell-which-service-packs-have-been-installed-on-a-computer\/","title":{"rendered":"How Can I Tell Which Service Packs Have Been Installed 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 service packs have been installed on my computers?<BR><BR>&#8212; FR<\/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, FR. That\u2019s a very good question; as you know better than we do, in this day and age it\u2019s really important to make sure all your computers have the latest service pack, the latest hot fixes, and the latest downloads from Windows Update installed. But, like you said, how can you do that?<\/P>\n<P>Ah, you\u2019re way ahead of us: yes, scripting <I>is<\/I> a good way to track this information. For example, this simple script reports the latest service pack installed 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 colOperatingSystems = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_OperatingSystem&#8221;)\nFor Each objOperatingSystem in colOperatingSystems\n    Wscript.Echo objOperatingSystem.ServicePackMajorVersion  _\n        &amp; &#8220;.&#8221; &amp; objOperatingSystem.ServicePackMinorVersion\nNext\n<\/PRE>\n<P>Now you might be thinking, \u201cOh, the <I>latest<\/I> service pack. But I need to know about <I>all<\/I> the service packs that have been installed on a computer.\u201d If that\u2019s the case, relax; when you install, say, Service Pack 3.0, you automatically get everything that was included in Service Packs 1.0 and 2.0. Because of that, it doesn\u2019t really matter whether Service Pack 1.0 was installed; by installing Service Pack 3.0, you got all the functionality of Service Pack 1.0. Which is a somewhat convoluted way of saying that all you really care about is the latest service pack that was installed on a computer. And the preceding script will do just that.<\/P>\n<P>But what about those hot fixes we mentioned; how can you audit a computer and see which hot fixes have been installed? Try this script:<\/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 colQuickFixes = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_QuickFixEngineering&#8221;)\nFor Each objQuickFix in colQuickFixes\n    Wscript.Echo &#8220;Computer: &#8221; &amp; objQuickFix.CSName\n    Wscript.Echo &#8220;Description: &#8221; &amp; objQuickFix.Description\n    Wscript.Echo &#8220;Hot Fix ID: &#8221; &amp; objQuickFix.HotFixID\n    Wscript.Echo &#8220;Installation Date: &#8221; &amp; objQuickFix.InstallDate\n    Wscript.Echo &#8220;Installed By: &#8221; &amp; objQuickFix.InstalledBy\nNext\n<\/PRE>\n<P>Two things to keep in mind here. First, hot fixes haven\u2019t always been released in standard fashion. That doesn\u2019t mean they don\u2019t work, it just means that some hot fixes might not populate all the above fields; for example, many hot fixes won\u2019t return a value for the InstallDate property. Second, hot fix information is recorded in several places on your computer and, because there hasn\u2019t always been a standard way of doing this, WMI checks all of these locations and retrieves hot fix information. That\u2019s good, except that once in awhile a hot fix will actually record information in multiple locations. Again, that\u2019s not really a problem; it just means that when you get your information back from WMI you might see or 2 or 3 instances of hot fix QFE 1111111. That\u2019s because QFE 1111111 recorded information about itself in several different spots.<\/P>\n<P>Hey, that\u2019s right: we <I>did<\/I> mention Windows Update, didn\u2019t we? Well, if you\u2019ve installed the latest version of Windows Update, you might very well have a new COM object that enables you to retrieve update information. For example:<\/P><PRE class=codeSample>Set objSession = CreateObject(&#8220;Microsoft.Update.Session&#8221;)\nSet objSearcher = objSession.CreateUpdateSearcher\nintHistoryCount = objSearcher.GetTotalHistoryCount\n&#8216;Wscript.Echo intHistoryCount<\/p>\n<p>Set colHistory = objSearcher.QueryHistory(1, intHistoryCount)<\/p>\n<p>For Each objEntry in colHistory\n    Wscript.Echo &#8220;Operation: &#8221; &amp; objEntry.Operation\n    Wscript.Echo &#8220;Result code: &#8221; &amp; objEntry.ResultCode\n    Wscript.Echo &#8220;Date: &#8221; &amp; objEntry.Date\n    Wscript.Echo &#8220;Title: &#8221; &amp; objEntry.Title\n    Wscript.Echo &#8220;Description: &#8221; &amp; objEntry.Description\n    Wscript.Echo &#8220;Client application ID: &#8221; &amp; objEntry.ClientApplicationID\n    Wscript.Echo &#8220;Server selection: &#8221; &amp; objEntry.ServerSelection\n    Wscript.Echo &#8220;Service ID: &#8221; &amp; objEntry.ServiceID\n    i = 1\n    For Each strStep in objEntry.UninstallationSteps\n        Wscript.Echo i &amp; &#8221; &#8212; &#8221; &amp; strStep\n        i = i + 1\n    Next\n    Wscript.Echo &#8220;Uninstallation notes: &#8221; &amp; objEntry.UninstallationNotes\n    Wscript.Echo &#8220;Support URL: &#8221; &amp; objEntry.SupportURL\n    Wscript.Echo\nNext\n<\/PRE>\n<P>To be honest, we only know for sure that the Microsoft.Update.Session object gets installed on Windows XP (and is automatically installed when you install XP Service Pack 2). If you\u2019re running Windows 2000, you might want to visit Windows Update, install the latest version, then run the preceding script and see if it works.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I tell which service packs have been installed on my computers?&#8212; FR Hey, FR. That\u2019s a very good question; as you know better than we do, in this day and age it\u2019s really important to make sure all your computers have the latest service pack, the latest hot fixes, and [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-85949","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I tell which service packs have been installed on my computers?&#8212; FR Hey, FR. That\u2019s a very good question; as you know better than we do, in this day and age it\u2019s really important to make sure all your computers have the latest service pack, the latest hot fixes, and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85949","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=85949"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85949\/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=85949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=85949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=85949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}