{"id":63773,"date":"2007-10-18T04:25:00","date_gmt":"2007-10-18T04:25:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/10\/18\/hey-scripting-guy-how-can-i-tell-if-a-computer-is-bluetooth-enabled\/"},"modified":"2007-10-18T04:25:00","modified_gmt":"2007-10-18T04:25:00","slug":"hey-scripting-guy-how-can-i-tell-if-a-computer-is-bluetooth-enabled","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-tell-if-a-computer-is-bluetooth-enabled\/","title":{"rendered":"Hey, Scripting Guy! How Can I Tell if a Computer is Bluetooth-Enabled?"},"content":{"rendered":"<p><H2><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\"> <\/H2>\n<P>Hey, Scripting Guy! How can I tell if a computer is Bluetooth-enabled?<BR><BR>&#8212; RR<\/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, RR. You know, any time the Scripting Guys get asked something like this, one question immediately pops into <I>our<\/I> minds: \u201cSo where <I>did<\/I> the name Bluetooth come from anyway?\u201d<\/P>\n<P>As it turns out, the Bluetooth \u201cpersonal area networking\u201d protocol was named in honor of Harald Bluetooth Gormson, son of King Gorm the Old, the one time King of Jutland. (We\u2019re not sure if Gorm the Old is the name that the King was given at birth; that would be pretty cool, though, wouldn\u2019t it?) We found it interesting that Harald\u2019s <I>middle<\/I> name was Bluetooth. After all, Scripting Guy Jean Bluetooth Ross has spent her entire life (79 years and counting) thinking she was the only person to have that middle name. Good news, Jean: you\u2019re not the only Bluetooth after all. <\/P>\n<P>At any rate, Harald became King sometime around 958, upon the death of his father. Over time, Harald conquered all of modern-day Denmark and Norway, and, along the way, kind of, sort of converted to Christianity. He had a son named Sweyn Forkbeard who, no doubt in retaliation for being given the name Sweyn Forkbeard, eventually led a revolt that cost his father both his throne and his life. <\/P>\n<P>But Harald got the last laugh; after all, how many Forkbeard-enabled devices do you see these days?<\/P>\n<TABLE id=\"EJD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. There seems to be some disagreement as to where the name Bluetooth came from. Some scholars insist it comes from the old Norse words for \u201cdark-skinned\u201d and \u201cgreat man,\u201d meaning that Harald had dark skin and, well, was a great man. Others say it\u2019s because Harald actually <I>had<\/I> a blue tooth. Fortunately, Peter Costantini, the oldest living Scripting Guy, went to junior high school with Harald, so we\u2019ll ask Peter about that.<\/P>\n<P>Just as soon as he wakes up from his nap.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After we disposed of the question \u201cWhere did the name Bluetooth come from?\u201d a second question popped into our heads: how <I>can<\/I> you tell if a computer is Bluetooth-enabled? That turned out to be a much tougher question to answer; in fact, we never did find anything that could tell us definitively whether or not a computer was Bluetooth-enabled. (Or at least not a definitive way to do this programmatically; it\u2019s easy enough to verify that a computer is Bluetooth-enabled by using the Windows Control Panel.) However, based on the fact that Bluetooth <I>is<\/I> a network protocol, we managed to come up with the following a script, a script that correctly determined whether a handful of test computers were Bluetooth-enabled:<\/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 _\n    (&#8220;Select * From Win32_NetworkProtocol&#8221;)<\/p>\n<p>For Each objItem in colItems\n    If InStr(objItem.Name, &#8220;Bluetooth&#8221;) Then\n        Wscript.Echo &#8220;Description: &#8221; &amp; objItem.Description\n        Wscript.Echo &#8220;Name: &#8221; &amp; objItem.Name\n    End If\nNext\n<\/PRE>\n<P>So what are we doing here? Well, to begin with, we\u2019re connecting to the WMI service on the local computer. And yes, you can just as easily run this script against a remote computer; all you need to do is assign the name of that remote machine to the variable strComputer:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-ws-01&#8221;\n<\/PRE>\n<P>After making the connection to the WMI service, we then use the following query to return a collection of all the network protocols installed on the computer:<\/P><PRE class=\"codeSample\">Set colItems = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_NetworkProtocol&#8221;)\n<\/PRE>\n<P>Is that the answer to our question? No, but we <I>are<\/I> getting closer.<\/P>\n<P>To actually find the answer, we next set up a For Each loop to loop through the collection of network adapters. What do we do inside that loop? Well, for starters, we execute this line of code:<\/P><PRE class=\"codeSample\">If InStr(objItem.Name, &#8220;Bluetooth&#8221;) Then\n<\/PRE>\n<P>Here we\u2019re using VBScript\u2019s <B>InStr<\/B> function to search the value of the protocol <B>Name<\/B> property. And what are we searching for? Why, the string value <I>Bluetooth<\/I>, of course. If InStr returns a 0, that means it failed to find the word <I>Bluetooth<\/I> anywhere in the protocol Name; in that case, we zip back to the top of the loop and repeat the process with the next protocol in the collection. If InStr returns anything other than 0, that means that the target word <I>was<\/I> found in the value of the Name property. In that case, we then echo back the values of the protocol <B>Description<\/B> and Name, like so:<\/P><PRE class=\"codeSample\">Description: Bluetooth Device (RFCOMM Protocol TDI)\nName: MSAFD RfComm [Bluetooth]\n<\/PRE>\n<P>As best we can tell, the presence of this protocol means that the computer is Bluetooth-enabled; this protocol <I>appears<\/I> to be installed only on computers that are capable of running Bluetooth. We can\u2019t guarantee that this is the case, but, like we said, it worked on our admittedly-limited number of test machines.<\/P>\n<P>OK. Next question: is there any way to tell if a particular Bluetooth device is installed on a computer? That\u2019s another tough one; unfortunately there\u2019s no such thing as a Win32_Bluetooth class that collects information about Bluetooth devices. That\u2019s definitely a shame; that would be a useful class. However, one thing you <I>can<\/I> do is use WMI classes that <I>do<\/I> exist to look for the presence of a Bluetooth device. For example, this script uses the <B>Win32_NetworkAdapter<\/B> class to see if the computer has any Bluetooth adapters installed:<\/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_NetworkAdapter&#8221;)<\/p>\n<p>For Each objItem in colItems\n    If InStr(objItem.Caption, &#8220;Bluetooth&#8221;) Then\n        Wscript.Echo &#8220;Caption: &#8221; &amp; objItem.Caption\n        Wscript.Echo &#8220;Device ID: &#8221; &amp; objItem.DeviceID\n        Wscript.Echo &#8220;Name: &#8221; &amp; objItem.Name\n    End If\nNext\n<\/PRE>\n<P>How does this script work? Pretty much the same way our first script did; the only difference is that this one uses InStr to see if the word <I>Bluetooth<\/I> appears anywhere in the <B>Caption<\/B> property for each network adapter installed on the computer. On our test machine, this script returns the following:<\/P><PRE class=\"codeSample\">Caption: [00000016] Bluetooth Device (Personal Area Network)\nDevice ID: 16\nName: Bluetooth Device (Personal Area Network)\n<\/PRE>\n<P>You could do something similar for the <B>Win32_POTSModem<\/B> class to see if the computer has a Bluetooth-enabled modem. And so on.<\/P>\n<TABLE id=\"EAG\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. Although these products are not available yet, at last not in the US, Toshiba apparently makes Bluetooth-enabled microwaves, refrigerators, and washers and dryers. That\u2019s the good news. The bad news? WMI doesn\u2019t have a Win32_WasherAndDryer class, either.<\/P>\n<P>At least not yet. Maybe in Windows Server 2008.<\/P>\n<P><B>Ed<\/B><B>itor\u2019s Note<\/B> (for the humor-challenged at Microsoft): No, we\u2019re not really telling anybody there will be a Win32_WasherAndDryer class in Windows Server 2008. We said \u201cmaybe.\u201d<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>We hope that helps, RR. For those of you more interested in Harlald Bluetooth than Bluetooth devices, we should point out that, following his death, Harald was buried in the cathedral at Roskilde. Interestingly enough, Roskilde is also be the home of the Roskilde Festival, one of the two biggest rock music festivals in all of Europe. (Which, now that we think about it, is probably why they named it the Roskilde Festival.) In the year 2007 the Roskilde Festival was marked by the appearance of big-name groups such as the Who, the Beastie Boys, and the Red Hot Chili Peppers, as well as the nearly 4 inches of rain that fell during the festival\u2019s 4 days.<\/P>\n<P>And yes, that <I>would<\/I> be just another Saturday afternoon for those of us in the Seattle area. Or at least lately it would be.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I tell if a computer is Bluetooth-enabled?&#8212; RR Hey, RR. You know, any time the Scripting Guys get asked something like this, one question immediately pops into our minds: \u201cSo where did the name Bluetooth come from anyway?\u201d As it turns out, the Bluetooth \u201cpersonal area networking\u201d protocol was named [&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":[16,47,3,5],"class_list":["post-63773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-general-management-tasks","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I tell if a computer is Bluetooth-enabled?&#8212; RR Hey, RR. You know, any time the Scripting Guys get asked something like this, one question immediately pops into our minds: \u201cSo where did the name Bluetooth come from anyway?\u201d As it turns out, the Bluetooth \u201cpersonal area networking\u201d protocol was named [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63773","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=63773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63773\/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=63773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=63773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=63773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}