{"id":2639,"date":"2013-02-22T13:51:55","date_gmt":"2013-02-22T19:51:55","guid":{"rendered":"http:\/\/www.jasemccarty.com\/blog\/?p=2639"},"modified":"2013-03-21T07:50:48","modified_gmt":"2013-03-21T13:50:48","slug":"a-few-bginfo-vbscripts-for-my-vms","status":"publish","type":"post","link":"https:\/\/www.jasemccarty.com\/blog\/a-few-bginfo-vbscripts-for-my-vms\/","title":{"rendered":"A few BGInfo VBScripts for my VMs"},"content":{"rendered":"<p>I saw Ivo Beerens&#8217; blog post about using <strong><a title=\"BgInfo\" href=\"http:\/\/technet.microsoft.com\/en-us\/sysinternals\/bb897557http:\/\/\" target=\"_blank\">BGInfo<\/a><\/strong> and VMware View: <a title=\"Display the protocol used on the VMware View desktop background\" href=\"http:\/\/www.ivobeerens.nl\/2013\/02\/21\/display-the-protocol-used-on-the-vmware-view-desktop-background\/\" target=\"_blank\"><strong>Display the protocol used on the VMware View desktop background<\/strong><\/a> and it made me think of some of the scripts I&#8217;ve used. I figured I would share them.<\/p>\n<p>I&#8217;ve used BGInfo for years, and have collected several scripts that I have used for various pieces of info that isn&#8217;t always the easiest to get from either the Windows registry or other places.\u00a0 When I worked for a Service Provider, it wasn&#8217;t uncommon to have systems spread across different Windows versions, multiple time zones, 64 or 32 bit, etc.<\/p>\n<p>Here are some of the scripts I regularly used when I was an Administrator.<\/p>\n<p><strong>System Type<\/strong> &#8211; Displays the Hardware Manufacturer &amp; Model Type<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nConst wbemFlagReturnImmediately = &amp;h10\r\nConst wbemFlagForwardOnly = &amp;h20\r\n\r\n'*** Connect to this PC's WMI Service\r\nSet objWMI = GetObject(&quot;winmgmts:\\\\.\\root\\CIMV2&quot;)\r\n\r\n'*** Query WMI for Hardware\r\nSet items = objWMI.ExecQuery(&quot;SELECT * FROM Win32_ComputerSystemProduct&quot;, _\r\n&quot;WQL&quot;, wbemFlagReturnImmediately + wbemFlagForwardOnly)\r\n\r\nFor Each item In items\r\nstrSystemType = item.Vendor &amp; &quot; &quot; &amp; item.Name 'What we're after\r\nNext\r\n\r\nIf Len(strSystemType) = 0 Then strSystemType = &quot;Not Found in WMI&quot;\r\n\r\necho strSystemType\r\n<\/pre>\n<p><strong><!--more-->Windows Version<\/strong> &#8211; Display the version of Windows<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nConst wbemFlagReturnImmediately = &amp;h10\r\nConst wbemFlagForwardOnly = &amp;h20\r\n\r\n'*** Connect to this PC's WMI Service\r\nSet objWMI = GetObject(&quot;winmgmts:\\\\.\\root\\CIMV2&quot;)\r\n\r\n'*** Query WMI\r\nSet Items = objWMI.ExecQuery(&quot;SELECT Caption FROM Win32_OperatingSystem&quot;,_\r\n&quot;WQL&quot;, wbemFlagReturnImmediately + wbemFlagForwardOnly)\r\n\r\nFor Each Item In Items\r\nstrWinVer = Item.Caption 'What we're after\r\nNext\r\n\r\n'*** Clean up the text\r\nstrWinVer = Replace(strWinVer,&quot;Microsoft&quot;,&quot;&quot;) 'strip off MSFT\r\nstrWinVer = Replace(strWinVer,&quot;(R)&quot;,&quot;&quot;) 'strip off (R)\r\nstrWinVer = Trim(strWinVer) ' Remove leading\/trailing spaces\r\n\r\nIf Len(strWinVer) = 0 Then strWinVer = &quot;Not Found in WMI&quot;\r\n\r\nSet WSHShell = CreateObject(&quot;WScript.Shell&quot;)\r\n\r\nIf Right(ProductName,2) = &quot;R2&quot; Then\r\n   strWinVer = Replace(strWinVer,&quot;, &quot;,&quot; R2, &quot;)\r\nEnd If\r\n\r\nEcho strWinVer\r\n<\/pre>\n<p><strong>Time Zone <\/strong>&#8211; The Current Time Zone (with support for Daylight Saving Time)<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nConst wbemFlagReturnImmediately = &amp;h10\r\nConst wbemFlagForwardOnly = &amp;h20\r\n\r\n'*** Connect to this PC's WMI Service\r\nSet objWMI = GetObject(&quot;winmgmts:\\\\.\\root\\CIMV2&quot;)'Dot is local computer\r\n\r\n'*** Query WMI\r\nSet Win32Computer = objWMI.ExecQuery(&quot;SELECT * FROM Win32_ComputerSystem&quot;)\r\n\r\nFor Each Item In Win32Computer\r\nDaySave = Item.DaylightInEffect\r\nNext\r\n\r\nSet Items = objWMI.ExecQuery(&quot;SELECT * FROM Win32_TimeZone&quot;)\r\n\r\nFor Each TimeItem In Items\r\n   DayDST = TimeItem.DaylightName\r\n   DaySTD = TimeItem.StandardName\r\nNext\r\n\r\nIf DaySave &lt;&gt; &quot;True&quot; then\r\n   DST = DaySTD\r\nElse\r\n   DST = DayDST\r\nEnd If\r\n\r\nEcho DST\r\n<\/pre>\n<p><strong>x64<\/strong> &#8211; Display whether a system is 64-bit or not<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSet WshShell = CreateObject(&quot;WScript.Shell&quot;)\r\nSet WshSysEnv = WshShell.Environment(&quot;System&quot;)\r\n\r\nIf WshSysEnv(&quot;PROCESSOR_ARCHITECTURE&quot;) = &quot;AMD64&quot; then\r\n   Echo &quot;64-bit System&quot;\r\nElse\r\n   Echo &quot;32-bit System&quot;\r\nEnd If\r\n<\/pre>\n<p><strong>GetNotes<\/strong> &#8211; Read the contents of a file named C:\\notes.txt so I can display whatever I wish<br \/>\n<em>*I typically would put the role of the server, or any nuances of the application in this file<\/em><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSet objFS = CreateObject(&quot;Scripting.fileSystemObject&quot;)\r\nif objFS.FileExists(&quot;C:\\notes.txt&quot;) Then\r\n   strNOTES = &quot;Notes:&quot; &amp; vbcrlf\r\n   Set objIN = objFS.OpenTextFile(&quot;C:\\notes.txt&quot;,1)\r\n\r\n   'Read everything in an array\r\n   inputData = Split(objIN.ReadAll, vbNewline)\r\n\r\n   For each strData In inputData\r\n      strNOTES = strNOTES &amp; strData &amp; vbcrlf\r\n   Next\r\n\r\n   objIN.Close\r\n   Echo StrNotes\r\nEnd If\r\nSet objFS = Nothing\r\n<\/pre>\n<p><strong>Mac Address<\/strong> &#8211; Read the Mac Address of adapters with IP enabled<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nConst wbemFlagReturnImmediately = &amp;h10\r\nConst wbemFlagForwardOnly = &amp;h20\r\n\r\n'*** Connect to this PC's WMI Service\r\nSet objWMI = GetObject(&quot;winmgmts:\\\\.\\root\\CIMV2&quot;)\r\n\r\n'*** Query WMI\r\nSet Win32MacAddr = objWMI.ExecQuery(&quot;SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True&quot;)\r\n\r\nFor Each Item In Win32MacAddr\r\n   MacAddr = Item.MACAddress\r\nNext\r\n\r\nEcho MacAddr\r\n<\/pre>\n<p><strong>As Of Date<\/strong> &#8211; A little script to return when this BGInfo script was last run<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nstrResult = formatDatetime(Date()) &amp; &quot; @ &quot; &amp; formatDatetime(Time(),3)\r\n\r\nEcho strResult\r\n<\/pre>\n<p>And some new ones I created after seeing <strong><a title=\"Display the protocol used on the VMware View desktop background\" href=\"http:\/\/www.ivobeerens.nl\/2013\/02\/21\/display-the-protocol-used-on-the-vmware-view-desktop-background\/\" target=\"_blank\">Ivo&#8217;s blog post<\/a><\/strong>.<\/p>\n<p><strong>View Broker<\/strong> &#8211; Display some View Broker info<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSet wshShell = CreateObject (&quot;Wscript.Shell&quot;)\r\n\r\necho &quot;Broker: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_DNS_Name%&quot;)\r\necho &quot;Domain: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_DomainName%&quot;)\r\necho &quot;Remote IP: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_Remote_IP_Address%&quot;)\r\necho &quot;Tunneled: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_Tunneled%&quot;)\r\necho &quot;Tunnel URL: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_Tunnel_URL%&quot;)\r\necho &quot;URL: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_URL%&quot;)\r\n<\/pre>\n<p><strong>View Client<\/strong> &#8211; Display some View Client info<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSet wshShell = CreateObject (&quot;Wscript.Shell&quot;)\r\n\r\necho &quot;View Client Username: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Broker_UserName%&quot;)\r\necho &quot;View Client IP Address: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_IP_Address%&quot;)\r\necho &quot;View Client LoggedOn Domain: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_LoggedOn_Domainname%&quot;)\r\necho &quot;View Client LoggedOn Username: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_LoggedOn_Username%&quot;)\r\necho &quot;View Client Machine Name: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Machine_Name%&quot;)\r\necho &quot;View Client MAC Address: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_MAC_Address%&quot;)\r\necho &quot;View Client Protocol: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Protocol%&quot;)\r\necho &quot;View Client Type: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Type%&quot;)\r\necho &quot;View Client Timezone: &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Windows_Timezone%&quot;)\r\n<\/pre>\n<p><strong>View Client Logged On As\/From<\/strong> &#8211; Display only who\/where a user is logged on from, and with what protocol<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSet wshShell = CreateObject (&quot;Wscript.Shell&quot;)\r\n\r\necho &quot;Logged on as &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_LoggedOn_Domainname%&quot;) &amp; &quot;\\&quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_LoggedOn_Username%&quot;)\r\necho &quot;From &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Machine_Name%&quot;) &amp; &quot; using &quot; &amp; wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Protocol%&quot;)\r\necho wshShell.ExpandEnvironmentStrings (&quot;%ViewClient_Windows_Timezone%&quot;)\r\n<\/pre>\n<p>To add any of these as an available option in BGInfo, it is pretty straightforward.\u00a0 Just follow these steps:<\/p>\n<ol>\n<li>Click Custom<\/li>\n<li>Click New<\/li>\n<li>Enter the Indentifier<\/li>\n<li>Select VB Script file<\/li>\n<li>Enter the path to the vbs<\/li>\n<li>Click Ok<\/li>\n<li>The new Identifier is available in the Fields selection window<\/li>\n<\/ol>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-2660\" alt=\"BGINFO\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO.png\" width=\"476\" height=\"347\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO.png 793w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO-300x218.png 300w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Here is a resulting BGInfo execution on the vCenter Server in my lab:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO-VC.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-2666\" alt=\"BGINFO-VC\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO-VC.png\" width=\"458\" height=\"402\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO-VC.png 572w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/BGINFO-VC-300x263.png 300w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">I hope they are useful to others as they have been useful to me.<\/p>\n<p style=\"text-align: left;\">Just a disclaimer&#8230; I haven&#8217;t tried any of these on Windows 2012&#8230;<\/p>\n<p style=\"text-align: left;\">Cheers,<br \/>\nJase<\/p>\n<p style=\"text-align: left;\"><strong>Update:<\/strong> In the comments section, Alexandru asked for how I was pulling the VMware Tools version.\u00a0 I&#8217;m simply pulling a file version from the vmtoolsd.exe executable.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/vmtools-ver.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-2751\" alt=\"vmtools-ver\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/vmtools-ver.png\" width=\"473\" height=\"367\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/vmtools-ver.png 789w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2013\/02\/vmtools-ver-300x232.png 300w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I saw Ivo Beerens&#8217; blog post about using BGInfo and VMware View: Display the protocol used on the VMware View desktop background and it made &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,11,14,12,13],"tags":[136,159,99,105,137],"class_list":["post-2639","post","type-post","status-publish","format-standard","hentry","category-citrix","category-vbs","category-vdi","category-virtualization","category-windows","tag-bginfo","tag-vdi","tag-view","tag-vmware","tag-xendesktop"],"_links":{"self":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/2639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/comments?post=2639"}],"version-history":[{"count":33,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/2639\/revisions"}],"predecessor-version":[{"id":2752,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/2639\/revisions\/2752"}],"wp:attachment":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/media?parent=2639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/categories?post=2639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/tags?post=2639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}