{"id":67493,"date":"2006-04-20T11:11:00","date_gmt":"2006-04-20T11:11:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/04\/20\/how-can-i-tell-which-of-our-windows-server-2003-computers-are-running-r2\/"},"modified":"2006-04-20T11:11:00","modified_gmt":"2006-04-20T11:11:00","slug":"how-can-i-tell-which-of-our-windows-server-2003-computers-are-running-r2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-tell-which-of-our-windows-server-2003-computers-are-running-r2\/","title":{"rendered":"How Can I Tell Which of Our Windows Server 2003 Computers are Running R2?"},"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! We have a bunch of Windows Server 2003 computers in our organization. Some of these computers are running Windows Server 2003 R2 and some are not. How can I tell which of our Windows Server 2003 computers are running R2?<BR><BR>&#8212; TX<\/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, TX. You know, that\u2019s a question that people have been trying to answer for hundreds and hundreds of years: how can I determine whether a computer is running Windows Server 2003 R2 or not? And we\u2019re not exaggerating here, either: after all, who could ever forget Julius Caesar\u2019s last words: \u201cR2, Brute?\u201d <\/P>\n<P>Now, if a Julius Caesar had no idea how to determine whether or not a computer is running Windows Server 2003 R2, what makes anyone think the Scripting Guys can succeed where even the mighty Caesar failed? Well, it\u2019s definitely true that Caesar had wealth, power, and a genius for military tactics. What he didn\u2019t have, however, was WMI:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_OperatingSystem&#8221;)<\/p>\n<p>For Each objItem in colItems\n    If InStr(objItem.OtherTypeDescription, &#8220;R2&#8221;) Then\n        WScript.Echo &#8220;This computer is running Windows Server 2003 R2.&#8221;\n    Else\n        WScript.Echo &#8220;This computer is not running Windows Server 2003 R2.&#8221;\n    End If\nNext\n<\/PRE>\n<P>Yes, we know: it seems like this script should be a little fancier than that, doesn\u2019t it? But this will do the trick, and in just a second we\u2019ll explain how, and why.<\/P>\n<P>The script starts off like most WMI scripts: it simply makes a connection to the WMI service on the local computer. (And, like most WMI scripts it can easily be modified to run against a remote computer: just assign the name of that remote computer to the variable strComputer.) We then use this line of code to retrieve information about the operating system currently in use on the machine:<\/P><PRE class=\"codeSample\">Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_OperatingSystem&#8221;)\n<\/PRE>\n<P>Now comes the part that will have people singing the praises of the Scripting Guys long after they have forgotten Julius Caesar. As it turns out, the <B>Win32_OperatingSystem<\/B> class includes a property named <B>OtherTypeDescription<\/B>. Throughout recorded history this property has always returned a Null value. (Try it on a computer running Windows 2000 Server or Windows XP or regular old Windows Server 2003. You\u2019ll always get back the same value: Null.) On a computer running Windows Server 2003 R2, however, this property <I>does<\/I> return a value. Not only that, but that value includes the string <B>R2<\/B>. And that\u2019s how you determine whether or not a computer is running R2: you simply check to see if the string R2 can be found anywhere within the OtherTypeDescription property.<\/P>\n<P>Needless to say, then, that\u2019s what we do with the rest of the script. We set up a For Each loop to walk through the collection of operating systems returned by our query. (There will be only one such operating system, but we still need to use a For Each loop, something which will <I>not<\/I> be the case in <A href=\"http:\/\/null\/technet\/scriptcenter\/topics\/vista\/indexer.mspx\"><B>Windows Vista<\/B><\/A>.) We then use the <B>InStr<\/B> function to check for the presence of the string R2 in the OtherTypeDescription property:<\/P><PRE class=\"codeSample\">If InStr(objItem.OtherTypeDescription, &#8220;R2&#8221;) Then\n<\/PRE>\n<P>If InStr returns True we report back the fact that the computer is running R2; otherwise we report back the fact that the computer is <I>not<\/I> running R2. That\u2019s all we have to do.<\/P>\n<P>So is this the most important script ever written? Well, we wouldn\u2019t go quite <I>that<\/I> far. On the other hand, Julius Caesar didn\u2019t know about the OtherTypeDescription property and look what happened to him. So on second thought \u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! We have a bunch of Windows Server 2003 computers in our organization. Some of these computers are running Windows Server 2003 R2 and some are not. How can I tell which of our Windows Server 2003 computers are running R2?&#8212; TX Hey, TX. You know, that\u2019s a question that people have been [&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,5,288],"class_list":["post-67493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-scripting-guy","tag-vbscript","tag-version-information"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! We have a bunch of Windows Server 2003 computers in our organization. Some of these computers are running Windows Server 2003 R2 and some are not. How can I tell which of our Windows Server 2003 computers are running R2?&#8212; TX Hey, TX. You know, that\u2019s a question that people have been [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67493","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=67493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67493\/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=67493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}