{"id":67843,"date":"2006-03-02T09:00:00","date_gmt":"2006-03-02T09:00:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/03\/02\/how-can-i-determine-if-a-computer-is-running-windows-server-2003-and-if-service-pack-1-is-installed\/"},"modified":"2006-03-02T09:00:00","modified_gmt":"2006-03-02T09:00:00","slug":"how-can-i-determine-if-a-computer-is-running-windows-server-2003-and-if-service-pack-1-is-installed","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-if-a-computer-is-running-windows-server-2003-and-if-service-pack-1-is-installed\/","title":{"rendered":"How Can I Determine if a Computer is Running Windows Server 2003 and if Service Pack 1 is Installed?"},"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 determine whether or not a computer is running Windows Server 2003 and, if so, whether Service Pack 1 is installed?<BR><BR>&#8212; TW<\/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, TW. You know, we Scripting Guys always get a kick out of questions like this. Not because there\u2019s anything wrong with the question, mind you. It\u2019s just that many of the people we work with would have no idea what you\u2019re talking about here. After all, why would you need a script like this one: of <I>course<\/I> you have Windows Server 2003 installed, and of <I>course<\/I> you\u2019ve got Service Pack 1 on there as well. I mean, even your laptops are running Windows Server 2003, Service Pack 1. Aren\u2019t they?<\/P>\n<P>We Scripting Guys like to think we\u2019re a little more in touch with reality than some of our fellow Microsoft employees. (Now <I>that\u2019s<\/I> something you don\u2019t hear every day!) We understand that people &#8211; for many valid reasons &#8211; don\u2019t always upgrade the very second that Microsoft releases a new product or a new version of a product. That\u2019s why, whenever possible, we try to provide a Windows 2000 workaround in those columns where we show people a Windows XP or Windows Server 2003 solution. And that\u2019s why we\u2019re more than happy to show you a script that can tell you whether a computer is running Windows Server 2003 and, if so, whether it has Service Pack 1 installed:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_OperatingSystem&#8221;)<\/p>\n<p>For Each objItem in colItems\n    If InStr(objItem.Caption, &#8220;Server 2003&#8221;) Then\n        strText = objItem.Caption \n        If objItem.ServicePackMajorVersion = &#8220;1&#8221; Then\n            strText = strText &amp; &#8220;, Service Pack 1&#8221;\n        End If\n        Wscript.Echo strText\n    Else\n        Wscript.Echo &#8220;This computer is not running Windows Server 2003.&#8221;\n    End If\nNext\n<\/PRE>\n<P>Pretty exciting, huh? The script starts out by connecting to the WMI service on the local computer; for those of you with multiple machines in multiple locations, this script can also be used to determine the operating system installed on a remote computer. We then use this line of code to retrieve a collection of all the operating systems installed on the computer:<\/P><PRE class=\"codeSample\">Set colItems = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_OperatingSystem&#8221;)\n<\/PRE>\n<TABLE id=\"EHD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. OK, we admit it: this query doesn\u2019t return a collection of <I>all<\/I> the operating systems installed on a computer; it only returns information about the operating system currently in use. That\u2019s true even if you have a multi-boot computer: you\u2019ll only be told about the current operating system, and won\u2019t even be aware that other OSes are installed on the machine.<\/P>\n<P>That\u2019s just the way it goes.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Even though there will be only one operating system in our collection we still need to set up a For Each loop to walk through that collection. Logically enough, then, we set up a For Each loop and then run this line of code:<\/P><PRE class=\"codeSample\">If InStr(objItem.Caption, &#8220;Server 2003&#8221;) Then\n<\/PRE>\n<P>What we\u2019re doing here is using the <B>InStr<\/B> function to determine whether or not the string <I>Server 2003<\/I> can be found anywhere in the <B>Caption<\/B> property. We do this because Windows Server 2003 comes in various flavors: Standard, Advanced, Enterprise, Windows Server 2003 R2, Caramel Nut Fudge. The one thing all these versions have in common (well, except for Caramel Nut Fudge, which might not actually <I>be<\/I> a version of the operating system) is that the string <I>Server 2003<\/I> appears somewhere in the caption. So that\u2019s what we check for: if the Caption has <I>Server 2003<\/I> in it then we assume it must be some flavor of Windows Server 2003. (And when we echo back the operating system information we\u2019ll specify <I>which<\/I> flavor.)<\/P>\n<TABLE id=\"EPE\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. In case you\u2019re wondering, no, we can\u2019t just use the BuildNumber property, because the build numbers can also vary depending on the operating system version.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>So what happens if we find the string <I>Server 2003<\/I> in the Caption? That\u2019s easy: we then store the entire Caption in a variable named strText. And because we <I>did<\/I> find the target string, that means that the computer in question must be running Windows Server 2003. Therefore, our next step is to see if the value of the <B>ServicePackMajorVersion<\/B> property is equal to 1; if it is, that means that Service Pack 1 is installed. That\u2019s what we do here:<\/P><PRE class=\"codeSample\">If objItem.ServicePackMajorVersion = &#8220;1&#8221; Then\n<\/PRE>\n<P>If this is true (that is, if Service Pack 1 is installed), then we tack a note to that effect to end of the variable strText. That means that a computer that has Service Pack 1 installed will echo back information similar to this:<\/P><PRE class=\"codeSample\">Microsoft(R) Windows(R) Server 2003, Standard Edition, Service Pack 1\n<\/PRE>\n<P>If the computer is running Windows Server 2003 but <I>doesn\u2019t<\/I> have Service Pack 1 installed then it will echo back something like this:<\/P><PRE class=\"codeSample\">Microsoft(R) Windows(R) Server 2003, Standard Edition\n<\/PRE>\n<P>See how that works? That\u2019s how we distinguish between a computer with Service Pack 1 and a computer without Service Pack 1.<\/P>\n<P>But what if the computer isn\u2019t running Windows Server 2003 at all? Well, in that case our script will skip down to the Else statement and echo this message:<\/P><PRE class=\"codeSample\">This computer is not running Windows Server 2003.\n<\/PRE>\n<P>Sure, we know: nobody would <I>ever<\/I> have a computer that wasn\u2019t running Windows Server 2003. But, just in case, we added this little feature to the script anyway. After all, if someone was abducted by aliens 6 years ago and were just recently returned, they might only now be getting around to installing Windows Server 2003 on all their machines. You never know.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I determine whether or not a computer is running Windows Server 2003 and, if so, whether Service Pack 1 is installed?&#8212; TW Hey, TW. You know, we Scripting Guys always get a kick out of questions like this. Not because there\u2019s anything wrong with the question, mind you. It\u2019s just [&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,203,5],"class_list":["post-67843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-scripting-guy","tag-service-packs-and-hotfixes","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I determine whether or not a computer is running Windows Server 2003 and, if so, whether Service Pack 1 is installed?&#8212; TW Hey, TW. You know, we Scripting Guys always get a kick out of questions like this. Not because there\u2019s anything wrong with the question, mind you. It\u2019s just [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67843","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=67843"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67843\/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=67843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}