<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Who... What... Where... &#187; VB</title>
	<atom:link href="http://www.yeltuor.com/articles/tag/vb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yeltuor.com</link>
	<description>General things I find interesting</description>
	<lastBuildDate>Sun, 02 Aug 2009 09:58:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>VB WMI Examples</title>
		<link>http://www.yeltuor.com/reference/vb-wmi-examples/</link>
		<comments>http://www.yeltuor.com/reference/vb-wmi-examples/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 14:50:06 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.yeltuor.com/?page_id=133</guid>
		<description><![CDATA[All below examples are based on establishing a connection to a remote computer and performing a WMI query.
Computer Disk Information
Retrieves information about all physical disks (distinguished by the numerical value 3), and displays ins volume identifier (drive letter) and free vs used space.
Const HARD_DISK = 3
Set objWMIService = GetObject(&#8220;winmgmts:&#8221; &#38; &#8220;{impersonationLevel=impersonate}!\\&#8221; &#38; &#8220;COMPUTER&#8221; &#38; &#8220;\root\cimv2&#8243;)
Set [...]]]></description>
			<content:encoded><![CDATA[<p>All below examples are based on establishing a connection to a remote computer and performing a WMI query.</p>
<h2><strong>Computer Disk Information</strong></h2>
<p>Retrieves information about all physical disks (distinguished by the numerical value 3), and displays ins volume identifier (drive letter) and free vs used space.</p>
<blockquote><p>Const HARD_DISK = 3</p>
<p>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; &amp; &#8220;{impersonationLevel=impersonate}!\\&#8221; &amp; &#8220;COMPUTER&#8221; &amp; &#8220;\root\cimv2&#8243;)</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Set colDisks = objWMIService.ExecQuery (&#8220;Select * from Win32_LogicalDisk Where DriveType = &#8221; &amp; HARD_DISK &amp; &#8220;&#8221;)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>For Each objDisk in colDisks</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>&#8216;objDisk.FreeSpace</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>&#8216;Wscript.Echo objDisk.DeviceID</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Wscript.Echo objDisk.DeviceID + &#8221; Disk Size (GB): &#8221; + CStr(Round((((objDisk.Size / 1024)/1024)/1024),1))</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Wscript.Echo objDisk.DeviceID + &#8221; Free Disk Space (GB): &#8221; + CStr(Round((((objDisk.FreeSpace / 1024)/1024)/1024),2))</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Next</div>
<p>Set colDisks = objWMIService.ExecQuery (&#8220;Select * from Win32_LogicalDisk Where DriveType = &#8221; &amp; HARD_DISK &amp; &#8220;&#8221;)</p>
<p><span style="white-space:pre"> </span>For Each objDisk in colDisks</p>
<p style="padding-left: 30px; "><span style="white-space:pre"> </span>Wscript.Echo objDisk.DeviceID + &#8221; Disk Size (GB): &#8221; + CStr(Round((((objDisk.Size / 1024)/1024)/1024),1))</p>
<p style="padding-left: 30px; "><span style="white-space:pre"> </span>Wscript.Echo objDisk.DeviceID + &#8221; Free Disk Space (GB): &#8221; + CStr(Round((((objDisk.FreeSpace / 1024)/1024)/1024),2))</p>
<p><span style="white-space:pre"> </span>Next</p></blockquote>
<h2>Network Card Information</h2>
<p>Retrieves information about the Network Cards configured on the computer, looping through all valid adapters present.</p>
<blockquote><p>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; &amp; &#8220;{impersonationLevel=impersonate}!\\&#8221; &amp; &#8220;COMPUTER&#8221; &amp; &#8220;\root\cimv2&#8243;)</p>
<p>Set colAdapters = objWMIService.ExecQuery (&#8220;Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE&#8221;)</p>
<p><span style="white-space: pre;"> </span>j = 1</p>
<p><span style="white-space: pre;"> </span>For Each objAdapter in colAdapters</p>
<p style="padding-left: 30px; ">Wscript.Echo &#8220;===Adapter &#8221; &amp; CStr(j)</p>
<p style="padding-left: 30px; ">If Not IsNull(objAdapter.IPAddress) Then</p>
<p style="padding-left: 60px;">For i=LBound(objAdapter.IPAddress) to UBound(objAdapter.IPAddress)</p>
<p style="padding-left: 90px;">Wscript.Echo &#8220;IP Address: &#8221; + objAdapter.IPAddress(i)</p>
<p style="padding-left: 90px;">WScript.Echo &#8220;Subnet: &#8221; &amp; objAdapter.IPSubnet(i)</p>
<p style="padding-left: 60px;">Next</p>
<p style="padding-left: 60px;">WScript.Echo &#8220;Gateway: &#8221; &amp; objAdapter.DefaultIPGateway(0)</p>
<p><span style="white-space: pre;"> </span></p>
<p style="padding-left: 60px;">For i = 0 To UBound(objAdapter.DNSServerSearchOrder)</p>
<p style="padding-left: 90px;">WScript.Echo &#8220;DNS Server: &#8221; &amp; objAdapter.DNSServerSearchOrder(i)</p>
<p style="padding-left: 60px;">Next</p>
<p style="padding-left: 60px;">
<p style="padding-left: 60px;">For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)</p>
<p style="padding-left: 90px;">WScript.Echo &#8220;DNS suffix list: &#8221; &amp; objAdapter.DNSDomainSuffixSearchOrder(i)</p>
<p style="padding-left: 60px;">Next<span style="white-space: pre;"> </span></p>
<p style="padding-left: 30px;">End If</p>
<p><span style="white-space: pre;"> </span>j = j+1</p>
<p>Next</p></blockquote>
<h2>Operating System / up-time Information</h2>
<p>Retrieves Information about the host operating system and current service pack, also information on the up-time of the host; be aware that if the regional settings differ the results may appear inaccurate.</p>
<blockquote><p>Set colOperatingSystems = objWMIService.ExecQuery (&#8220;Select * from Win32_OperatingSystem&#8221;)</p>
<p>For Each objOS in colOperatingSystems</p>
<p style="padding-left: 30px;">dtmBootup = objOS.LastBootUpTime</p>
<p style="padding-left: 30px;">dtmLastBootupTime = WMIDateStringToDate(dtmBootup)</p>
<p style="padding-left: 30px;">dtmSystemUptime = DateDiff(&#8220;n&#8221;, dtmLastBootUpTime, Now)</p>
<p style="padding-left: 30px;">Wscript.Echo &#8220;Uptime: &#8221; &amp; CStr(Round((dtmSystemUptime /60) /24)) &amp; &#8221; Day(s)&#8221;<span style="white-space:pre"> </span></p>
<p>Next</p>
<p>For Each objOperatingSystem in colOperatingSystems</p>
<p style="padding-left: 30px;">Wscript.Echo &#8220;OS: &#8221; &amp; objOperatingSystem.Caption &amp; &#8221; &#8221; &amp; objOperatingSystem.Version</p>
<p style="padding-left: 30px;">Wscript.Echo &#8220;Service Pack: &#8221; &amp; objOperatingSystem.ServicePackMajorVersion &amp; &#8220;.&#8221; &amp; objOperatingSystem.ServicePackMinorVersion</p>
<p>Next</p>
<p>Function WMIDateStringToDate(dtmBootup)</p>
<p style="padding-left: 30px;">WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) &amp; &#8220;/&#8221; &amp; _</p>
<p style="padding-left: 60px;">Mid(dtmBootup, 7, 2) &amp; &#8220;/&#8221; &amp; Left(dtmBootup, 4) _</p>
<p style="padding-left: 90px;">&amp; &#8221; &#8221; &amp; Mid (dtmBootup, 9, 2) &amp; &#8220;:&#8221; &amp; _</p>
<p style="padding-left: 120px;">Mid(dtmBootup, 11, 2) &amp; &#8220;:&#8221; &amp; Mid(dtmBootup,13, 2))</p>
<p>End Function<span style="white-space: pre;"> </span></p></blockquote>
<h2>Symantec Antivirus Definition Version</h2>
<p>This query has been tested on versions 7.x and 9.x. The principle is to connect to the remote file system and read the contents of the file named &#8220;definfo.dat&#8221; to define the date / version of the definitions loaded on the target computer.</p>
<blockquote><p>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)</p>
<p>Set objFile = objFSO.GetFile(&#8220;\\&#8221; &amp; &#8220;COMPUTER&#8221; &amp; &#8220;\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat&#8221;)</p>
<p>If objFSO.FileExists(objFile) Then</p>
<p style="padding-left: 30px;">Set objDatFile = objFSO.OpenTextFile(objFile, 1)</p>
<p style="padding-left: 30px;">Do Until objDatFile.AtEndOfStream</p>
<p style="padding-left: 60px;">strLine = objDatFile.Readline</p>
<p style="padding-left: 60px;">intCurDefs = InStr(strLine , &#8220;CurDefs&#8221;)</p>
<p><span style="white-space: pre;"> </span></p>
<p style="padding-left: 60px;">If intCurDefs &gt; 0 Then</p>
<p style="padding-left: 90px;">strCurDefs = strLine</p>
<p style="padding-left: 90px;">strDateDefs = Mid(strCurDefs, 9, 8 )</p>
<p style="padding-left: 90px;">dtYear = Left(strDateDefs, 4)</p>
<p style="padding-left: 90px;">dtMonth = Mid(strDateDefs, 5, 2)</p>
<p style="padding-left: 90px;">dtDay = Right(strDateDefs, 2)</p>
<p style="padding-left: 90px;">DateVirDefs = dtMonth &amp; &#8220;/&#8221; &amp; dtDay &amp; &#8220;/&#8221; &amp; dtYear</p>
<p style="padding-left: 90px;">dtDefDate = CDate(DatevirDefs)</p>
<p style="padding-left: 90px;">strRevNumber = Right(strCurDefs, 3)</p>
<p style="padding-left: 90px;">
<p style="padding-left: 90px;">Wscript.Echo &#8220;Definition: &#8221; &amp; dtDefDate &amp; &#8221; &#8221; &amp; strRevNumber</p>
<p style="padding-left: 60px;">End If</p>
<p style="padding-left: 30px;">Loop</p>
<p style="padding-left: 30px;">objDatFile.Close</p>
<p>Else</p>
<p style="padding-left: 30px;">Wscript.Echo &#8220;The file definfo.dat does not exist&#8221;</p>
<p>End If</p></blockquote>
<p>All of the above queries have been rolled up with into once script which also combines an <a title="VB Query Active Directory Objects" href="http://www.yeltuor.com/articles/script/vb-query-active-directory-objects/">AD query</a> element; this script can be downloaded <a title="Server_Info VBS File" href="http://www.yeltuor.com/files/Server_Info.vbs">here</a></p>

	Tags: <a href="http://www.yeltuor.com/articles/tag/active-directory/" title="Active Directory" rel="tag">Active Directory</a>, <a href="http://www.yeltuor.com/articles/tag/vb/" title="VB" rel="tag">VB</a>, <a href="http://www.yeltuor.com/articles/tag/wmi/" title="WMI" rel="tag">WMI</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.yeltuor.com/reference/vb-wmi-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB WMI Query Computer Attributes</title>
		<link>http://www.yeltuor.com/articles/script/vb-wmi-query-computer-attri/</link>
		<comments>http://www.yeltuor.com/articles/script/vb-wmi-query-computer-attri/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 09:58:13 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Scripting Snippets]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.yeltuor.com/?p=117</guid>
		<description><![CDATA[By using a VB scripts we can perform a WMI (Windows Management Instrumentation) connection to a host to execute a query against.
Below is an example of a WMI query connecting to the host named &#8220;computer&#8221;, once connected will loop around each drive letter which is a hard drive displaying the drive letter and total disk [...]]]></description>
			<content:encoded><![CDATA[<p>By using a VB scripts we can perform a WMI (Windows Management Instrumentation) connection to a host to execute a query against.</p>
<p>Below is an example of a WMI query connecting to the host named &#8220;computer&#8221;, once connected will loop around each drive letter which is a hard drive displaying the drive letter and total disk space in GB</p>
<blockquote><p>On Error Resume Next<br />
Const HARD_DISK = 3</p>
<p>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; &amp; &#8220;{impersonationLevel=impersonate}!\\&#8221; &amp; &#8220;computer&#8221; &amp; &#8220;\root\cimv2&#8243;)</p>
<p>if Err.Number = 0 then<br />
&#8216; Add WMI Query Script in here!</p>
<p>Set colDisks = objWMIService.ExecQuery (&#8220;Select * from Win32_LogicalDisk Where DriveType = &#8221; &amp; HARD_DISK &amp; &#8220;&#8221;)<br />
For Each objDisk in colDisks</p>
<p>Wscript.Echo objDisk.DeviceID + &#8221; Disk Size (GB): &#8221; + CStr(Round((((objDisk.Size / 1024)/1024)/1024),1))</p>
<p>Next</p>
<p>else<br />
Wscript.echo &#8220;Could not connect to &#8221; &amp; &#8220;computer&#8221; &amp; &#8221; error &#8221; &amp; Err.Number<br />
End If</p>
<p>Err.Clear</p></blockquote>
<p>The above WMI query can be combined with an Active Directory query to make the script more versatile (further information is <a href="http://www.yeltuor.com/articles/script/vb-query-active-directory-objects">here</a>), an example of this script is below:</p>
<blockquote><p>On Error Resume Next<br />
Const ADS_SCOPE_SUBTREE = 2<br />
Const HARD_DISK = 3</p>
<p>Set objConnection = CreateObject(&#8220;ADODB.Connection&#8221;)<br />
Set objCommand =   CreateObject(&#8220;ADODB.Command&#8221;)<br />
objConnection.Provider = &#8220;ADsDSOObject&#8221;<br />
objConnection.Open &#8220;Active Directory Provider&#8221;</p>
<p>Set objCOmmand.ActiveConnection = objConnection<br />
objCommand.CommandText = “Select Name from ‘LDAP://OU=MyServers,DC=Domain,DC=co,DC=uk’ ” &amp; “Where objectClass=’computer’”<br />
objCommand.Properties(”Page Size”) = 1000<br />
objCommand.Properties(”Searchscope”) = ADS_SCOPE_SUBTREE<br />
Set objRecordSet = objCommand.Execute<br />
objRecordSet.MoveFirst</p>
<p>Do Until objRecordSet.EOF<br />
Wscript.Echo &#8220;Computer Name: &#8221; &amp; objRecordSet.Fields(&#8220;Name&#8221;).Value</p>
<p>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; &amp; &#8220;{impersonationLevel=impersonate}!\\&#8221; &amp; objRecordSet.Fields(&#8220;Name&#8221;).Value &amp; &#8220;\root\cimv2&#8243;)</p>
<p>if Err.Number = 0 then</p>
<p>&#8216; Add WMI Query Script in here!</p>
<p>else<br />
Wscript.echo &#8220;Could not connect to &#8221; &amp; objRecordSet.Fields(&#8220;Name&#8221;).Value &amp; &#8221; error &#8221; &amp; Err.Number<br />
End If</p>
<p>Err.Clear<br />
objRecordSet.MoveNext<br />
Loop</p></blockquote>
<p>A number of WMI queries used can be found in the reference page <a href="http://www.yeltuor.com/">WMI_Queries</a></p>

	Tags: <a href="http://www.yeltuor.com/articles/tag/active-directory/" title="Active Directory" rel="tag">Active Directory</a>, <a href="http://www.yeltuor.com/articles/tag/vb/" title="VB" rel="tag">VB</a>, <a href="http://www.yeltuor.com/articles/tag/wmi/" title="WMI" rel="tag">WMI</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.yeltuor.com/articles/script/vb-wmi-query-computer-attri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB Query Active Directory Objects</title>
		<link>http://www.yeltuor.com/articles/script/vb-query-active-directory-objects/</link>
		<comments>http://www.yeltuor.com/articles/script/vb-query-active-directory-objects/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 19:56:58 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Scripting Snippets]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.yeltuor.com/?p=89</guid>
		<description><![CDATA[In an Active Directory environment there is often a requirement to query objects within the AD  database, either returning selected attribute values or using this information to for further queries.
The same principles apply across any object type, the script below connects via LDAP, performs a query and returns selected values from Active Directory.
The below script [...]]]></description>
			<content:encoded><![CDATA[<p>In an Active Directory environment there is often a requirement to query objects within the AD  database, either returning selected attribute values or using this information to for further queries.</p>
<p>The same principles apply across any object type, the script below connects via LDAP, performs a query and returns selected values from Active Directory.</p>
<p>The below script will query all objects in the OU <em>MyServers</em> and subtree, in the domain <em>Domain.co.uk</em>, of type <em>computer</em>, returning the attributes <em>Name </em>and <em>Location</em>.</p>
<blockquote><p>Const ADS_SCOPE_SUBTREE = 2</p>
<p>Set objConnection = CreateObject(”ADODB.Connection”)<br />
Set objCommand = CreateObject(”ADODB.Command”)<br />
objConnection.Provider = “ADsDSOObject”<br />
objConnection.Open “Active Directory Provider”</p>
<p>Set objCOmmand.ActiveConnection = objConnection<br />
objCommand.CommandText = “Select Name, Location from ‘LDAP://OU=MyServers,DC=Domain,DC=co,DC=uk’ ” &amp; “Where objectClass=’computer’”<br />
objCommand.Properties(”Page Size”) = 1000<br />
objCommand.Properties(”Searchscope”) = ADS_SCOPE_SUBTREE<br />
Set objRecordSet = objCommand.Execute<br />
objRecordSet.MoveFirst<br />
Do Until objRecordSet.EOF</p>
<p>‘ Insert Operators here<br />
objRecordSet.MoveNext</p>
<p>Loop</p></blockquote>
<p>Once the query has been run the results can then be used for any requirement, a simple example below is to display  the name of the computer followed by the Location attribute stored in AD.</p>
<blockquote><p>……<br />
Do Until objRecordSet.EOF</p>
<p>‘ Insert Operators here<br />
Wscript.Echo “Computer Name: ” &amp; objRecordSet.Fields(”Name”).Value<br />
Wscript.Echo “Location: ” &amp; objRecordSet.Fields(”Location”).Value</p>
<p>objRecordSet.MoveNext<br />
Loop</p></blockquote>
<p>Any attribute of the object can be displayed as long as it was requested in the initial query; <em>Select Name, Location from….</em> , attribute names are LDAP attributes rather than field names seen in the Active Directory Users and Computers mmc. A list of attributes can be found here; <a href="http://www.yeltuor.com/reference/active-directory-ldap-attributes/">Active Directory LDAP Attributes</a></p>
<p>One way to enhance this script further is for each computer selected perform a WMI query against it; <a href="http://www.yeltuor.com/">VB WMI Query</a></p>

	Tags: <a href="http://www.yeltuor.com/articles/tag/active-directory/" title="Active Directory" rel="tag">Active Directory</a>, <a href="http://www.yeltuor.com/articles/tag/ldap/" title="LDAP" rel="tag">LDAP</a>, <a href="http://www.yeltuor.com/articles/tag/vb/" title="VB" rel="tag">VB</a>, <a href="http://www.yeltuor.com/articles/tag/windows/" title="Windows" rel="tag">Windows</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.yeltuor.com/articles/script/vb-query-active-directory-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
