{"id":71453,"date":"2004-09-13T07:14:00","date_gmt":"2004-09-13T07:14:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/09\/13\/why-doesnt-my-like-query-work-on-windows-2000\/"},"modified":"2004-09-13T07:14:00","modified_gmt":"2004-09-13T07:14:00","slug":"why-doesnt-my-like-query-work-on-windows-2000","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/why-doesnt-my-like-query-work-on-windows-2000\/","title":{"rendered":"Why Doesn&#039;t My LIKE Query Work on Windows 2000?"},"content":{"rendered":"<p><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>Hey, Scripting Guy! I\u2019m trying to use a LIKE query in my WMI scripts. The query works fine on Windows XP computers, but I can\u2019t get it work on Windows 2000 computers. Do you know what I\u2019m doing wrong?<\/p>\n<p>&#8212; GS<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><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\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" 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><\/p>\n<p>Hey, GS. Actually you\u2019re not doing anything wrong. You\u2019re using a script similar to this, which uses the LIKE operator to search for all the files on a computer whose file name includes a ~ (these are almost always temporary files):<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject _\n    (\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\nSet colFiles = objWMIService.ExecQuery _\n    (\"Select * from CIM_DataFile where FileName Like '%~%'\")\nFor Each objFile in colFiles\n    Wscript.Echo objFile.Name\nNext\n<\/pre>\n<p>And you\u2019re right: this works great on Windows XP and Windows Server 2003, and we encourage people to take advantage of this new capability; it can be incredibly useful. However, those are the <i>only<\/i> two platforms which support the LIKE operator; this script won\u2019t work on Windows 2000 (or Windows NT 4.0 or Windows 98) because those platforms don\u2019t support the LIKE operator. And, before you ask, there are no plans to issue an update to older versions of Windows so that they <i>will<\/i> support this capability. Sorry; we wish there were such plans, too.<\/p>\n<p>So is there a workaround for this problem? Well, kind of, but it\u2019s not a particularly good one. About the best you can do is return a list of <i>all<\/i> the files on a computer, and then use the VBScript function InStr to see if the tilde appears in any of the file names. The following script does just that, although to ensure that the script runs a bit faster we added a WHERE clause that limits the search solely to the Scripts folder. Otherwise, the script would return a list of <i>all<\/i> the files on the computer, something we don\u2019t want to do in a testing situation:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject _\n    (\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\nSet colFiles = objWMIService.ExecQuery _\n    (\"Select * from CIM_DataFile WHERE Path = '\\\\Scripts\\\\'\")\nFor Each objFile in colFiles\n    If InStr(objFile.Name,\"~\") &lt;&gt; 0 Then\n        Wscript.Echo objFile.Name\n    End If\nNext<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I\u2019m trying to use a LIKE query in my WMI scripts. The query works fine on Windows XP computers, but I can\u2019t get it work on Windows 2000 computers. Do you know what I\u2019m doing wrong? &#8212; GS Hey, GS. Actually you\u2019re not doing anything wrong. You\u2019re using a script similar to [&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":[38,3,4,12,5,6],"class_list":["post-71453","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-files","tag-scripting-guy","tag-scripting-techniques","tag-storage","tag-vbscript","tag-wmi"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I\u2019m trying to use a LIKE query in my WMI scripts. The query works fine on Windows XP computers, but I can\u2019t get it work on Windows 2000 computers. Do you know what I\u2019m doing wrong? &#8212; GS Hey, GS. Actually you\u2019re not doing anything wrong. You\u2019re using a script similar to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71453","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=71453"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71453\/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=71453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}