<?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>Carlos&#039; Corner &#187; windows registry</title>
	<atom:link href="http://cars.lostroncos.org/tag/windows-registry/feed/" rel="self" type="application/rss+xml" />
	<link>http://cars.lostroncos.org</link>
	<description>The tired geek-dad in the corner</description>
	<lastBuildDate>Wed, 11 May 2011 03:33:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Simple Neverfail monitoring with Zabbix part 1</title>
		<link>http://cars.lostroncos.org/2009/05/31/simple-monitoring-of-neverfail-with-zabbix-part-1/</link>
		<comments>http://cars.lostroncos.org/2009/05/31/simple-monitoring-of-neverfail-with-zabbix-part-1/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 05:01:54 +0000</pubDate>
		<dc:creator>cars</dc:creator>
				<category><![CDATA[monitoring]]></category>
		<category><![CDATA[neverfail]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[zabbix]]></category>
		<category><![CDATA[neverfail for Exchange]]></category>
		<category><![CDATA[neverfail heartbeat]]></category>
		<category><![CDATA[reg_dword_big_endian]]></category>
		<category><![CDATA[windows registry]]></category>

		<guid isPermaLink="false">http://cars.lostroncos.org/?p=157</guid>
		<description><![CDATA[Background <p>This is the first of a couple of posts on how I&#8217;ve cobbled together some basic monitoring of Neverfail&#8217;s  Neverfail Heartbeat H/A software which is also now the basis for VMWare&#8217;s vCenter Server Heartbeat. Since Neverfail seems to consider their command lines privileged information I will only cover how to do some simple [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>This is the first of a couple of posts on how I&#8217;ve cobbled together some basic monitoring of <a href="http://www.neverfailgroup.com/">Neverfail&#8217;s  Neverfail Heartbeat H/A</a> software which is also now the basis for <a href="http://www.vmware.com/products/vcenter-server-heartbeat/">VMWare&#8217;s vCenter Server Heartbeat</a>. Since Neverfail seems to consider their command lines privileged information I will only cover how to do some simple monitoring using the registry. When starting on this effort internally I was only interested initially in figuring out a quick and simple way to get the info I needed and not so much on the how to get it into something part.</p>
<p>I&#8217;ve been working with another team where I work to look at Zabbix as an alternative for some of the monitoring we do in our environment. We use Microsoft Operations Manager 2005 (MOM) but haven&#8217;t fully cut over from out previous monitoring solution. I had looked at Zabbix earlier as a potential solution for monitoring a bunch of VMware ESX boxes but another team ended up getting tasked with that particular duty. So I had had some experience with Zabbix but hadn&#8217;t done too much with it since.</p>
<p>One of the things that&#8217;d been rattling around in my brain is using the capabilities of using the zabbix_sender feature/client to monitor some of other components/things we can&#8217;t easily get into MOM.  Zabbix_Sender is a utility that is available for use with Zabbix that allows one to &#8220;send&#8221; information to Zabbix. In my case it was appealing because we&#8217;re already running two different monitoring agents on the Exchange servers where we have Neverfail installed.  Since I only wanted to use Zabbix to monitor a small set of data related specifically to Neverfail zabbix_sender lets me do that without having to run the fullblown zabbix_agent as a service on the boxes.</p>
<p><span id="more-157"></span></p>
<h2>Getting the Data</h2>
<p>Neverfail (at least the versions we have installed) doesn&#8217;t obviously expose performance data. However if you look in the registry on each Neverfail server you will find some registry values (see <strong><em>HKLM\Software\Neverfail\R2\Performance</em></strong>) that get updated on a regular and frequent basis that correspond to data presented in the Neverfail GUI . Because of the way Neverfail works some of this data (Unsafe Queue info) is available on the Active node and some of it (Safe Queue info) is in the registry on the Passive node. This presents a couple of issues when trying to put together the solution (at least in my environment).</p>
<p>The first of these is trying to find a single consistent way to get the data out of the registry, especially since all the counters involved are of the REG_DWORD_BIG_ENDIAN variety (you can see a <a href="http://cars.lostroncos.org/2009/03/09/big_endian-registry-values/">previous entry related to BIG_ENDIAN here</a>).  I ended up settling on using the Reg.exe util available in Windows.  This utility let&#8217;s you manipulate the registry locally and remotely. While it doesn&#8217;t necessarily deal happily with REG_DWORD_BIG_ENDIAN (RDBE) entries in the registry it is able to extract the data which we can then manipulate to get the correct values.</p>
<p>As an example if I have the following two values in the registry as shown by RegEdit</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_example_01.png"><img class="alignnone size-full wp-image-159" title="reg_example_01" src="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_example_01.png" alt="reg_example_01" width="462" height="166" /></a></p>
<p>When I run <strong><em>reg.exe</em></strong> I get the following output&#8230;</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_query_rdword_rdbe.png"><img class="alignnone size-full wp-image-160" title="reg_query_rdword_rdbe" src="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_query_rdword_rdbe.png" alt="reg_query_rdword_rdbe" width="576" height="129" /></a></p>
<p>So while Dword_example and DWORD_BE_Example nominally have the same value <strong><em>reg.exe</em></strong> doesn&#8217;t get the data out correctly for the latter. However as I said earlier once we have the data out we can actually do some magic to get the right value.</p>
<p>We can also use <strong><em>reg.exe</em></strong> to get values on a remote machine (i.e. our Passive Neverfail node) by pre-pending the host info to the query registry path. So in this case to reach the passive secondary node over the private channel at 10.0.0.2 I can do something like  reg.exe Query \\10.0.0.2\CRT_CORP\Performance. Testing this out leads us to  a second issue. Getting an  &#8221;Acces is denied&#8221; error.</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_error_access_denied.png"><img class="alignnone size-full wp-image-158" title="reg_error_access_denied" src="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_error_access_denied.png" alt="reg_error_access_denied" width="592" height="176" /></a></p>
<p>Since my passive Neverfail node is essentially off-net but still thinks the network cables is live I can&#8217;t use a domain based account to run the reg.exe command because it can&#8217;t contact a domain controller to authenticate my domain account. However if I use the local Administrator account which has a common password on both nodes I can get this work just fine. (It may be possible to use an account other than the local Administrator but in my case where I also run some Neverfail command lines I need an account that&#8217;s authorized in Neverfail)</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_remote_as_admin.png"><img class="alignnone size-full wp-image-161" title="reg_remote_as_admin" src="http://cars.lostroncos.org/wp-content/uploads/2009/05/reg_remote_as_admin.png" alt="reg_remote_as_admin" width="528" height="188" /></a></p>
<p>Given this info I was able to put together a<a href="http://cars.lostroncos.org/?attachment_id=168"> </a><a href="http://cars.lostroncos.org/?attachment_id=172">vbscript that takes two arguments</a>: a reg path and a value name;  and it returns the data value to the console converting REG_DWORD and REG_DWORD_BIG_ENDIAN to the correct decimal value. Using <a href="http://cars.lostroncos.org/wp-content/uploads/2009/06/getregvaluevbs.txt">this script</a> it&#8217;s then possible to get  any of the counters we&#8217;re interested in on either the active or passive node.  So based on the example above where I ran <em>reg.exe hklm\software\CRT_CORP\Performance /s</em> we can run the script for each of the values and see that we do in fact get the right decimal value for each one.</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/06/getregvalue_example_01.png"><img class="alignnone size-full wp-image-176" title="getregvalue_example_01" src="http://cars.lostroncos.org/wp-content/uploads/2009/06/getregvalue_example_01.png" alt="getregvalue_example_01" width="702" height="213" /></a></p>
<p>So now the trick is to figure out which of the registry based perf values we want to use and which host we need to draw them from.  Each of the Neverfail nodes has the same set of values present even though they&#8217;re not all populated the same way. That is to say that the counters related to the Safe Queue are not updated on the Active node since the Safe Queue exists on the passive node. And the converse is true with regard to the UnsafeQueue counters.  As I was mostly interested in alerting related to an issue we have occur occassionally I really wanted to get the SafeQueue and UnsafeQueue related counters (OldestSafeUpdateQueueEntry, SafeUpdateQueueSize etc). But since the other counters are also equally easy to get I decided I to include several more.  The image below shows the available values.</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/05/nf_perf_reg_values.png"><img class="alignnone size-full wp-image-164" title="nf_perf_reg_values" src="http://cars.lostroncos.org/wp-content/uploads/2009/05/nf_perf_reg_values.png" alt="nf_perf_reg_values" width="481" height="337" /></a></p>
<p>So now that I have a simple way of getting the information I want I can focus on how to get it into whatever system I want to monitor with whether it&#8217;s Zabbix (now) or Systems Center Operations Manager 2007 (later).  In the next article(s) I&#8217;ll talk about setting up the Zabbix part of this monitoring.</p>
<p><strong><em>Acknowledgement: The hex to decimal routine in the GetRegValue.vbs script is lifted directly from </em></strong><strong><em><a href="http://www.sonofsofaman.com/hobbies/code/hextodec.asp">http://www.sonofsofaman.com/hobbies/code/hextodec.asp</a> Thanks to Joel for keeping me from having to reinvent the wheel. -crt</em></strong></p>
<p><strong>Addendum</strong>: While traipsing through the registry in figuring this stuff out I also discovered that there&#8217;s a bunch of configuration information stored in a whole different key under HKLM\Software\Javasoft\Prefs\neverfail\current\* It&#8217;s also possible to watch a few entries here to help monitor the  file and registry synchronization status even though it&#8217;s not as granular/descriptive/timely as can be obtained by using the command line.</p>
<p>The two items I&#8217;ve found that might be of interest are the <strong>/Registry/State/Manager\/Statu</strong>s Key and the <strong>/Value</strong> entry</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/06/reg_java_prefs_reg.png"><img class="alignnone size-full wp-image-183" title="reg_java_prefs_reg" src="http://cars.lostroncos.org/wp-content/uploads/2009/06/reg_java_prefs_reg.png" alt="reg_java_prefs_reg" width="725" height="212" /></a></p>
<p>and  the <strong>/New/File/State/Mgr\/Synchronization/Status</strong> key and <strong>/Tag</strong> entry</p>
<p><a href="http://cars.lostroncos.org/wp-content/uploads/2009/06/reg_java_prefs_file.png"><img class="alignnone size-full wp-image-182" title="reg_java_prefs_file" src="http://cars.lostroncos.org/wp-content/uploads/2009/06/reg_java_prefs_file.png" alt="reg_java_prefs_file" width="713" height="221" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://cars.lostroncos.org/2009/05/31/simple-monitoring-of-neverfail-with-zabbix-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Big_Endian values in the Windows Registry</title>
		<link>http://cars.lostroncos.org/2009/03/09/big_endian-registry-values/</link>
		<comments>http://cars.lostroncos.org/2009/03/09/big_endian-registry-values/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 23:41:07 +0000</pubDate>
		<dc:creator>cars</dc:creator>
				<category><![CDATA[monitoring]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[reg_dword_big_endian]]></category>
		<category><![CDATA[windows registry]]></category>

		<guid isPermaLink="false">http://cars.lostroncos.org/?p=97</guid>
		<description><![CDATA[<p>I was working today on trying to write some scripts to help me better monitor our various installations of Neverfail. The command line tools they provide don&#8217;t provide all the performance information I need but (strangely enough) they do write some of it into the Registry where it gets updated very frequently. In writing [...]]]></description>
			<content:encoded><![CDATA[<p>I was working today on trying to write some scripts to help me better monitor our various installations of Neverfail.  The command line tools they provide don&#8217;t provide all the performance information I need but (strangely enough) they do write some of it into the Registry where it gets updated very frequently.  In writing a Powershell script to read these values I was having issues with a set of the values I was reading.  Some values would be handled correctly and others were returning weird results. Below is an example of the &#8220;weird&#8221; ones.</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">PS</span> C:\Users\cars<span style="color: pink;">&gt;</span> <span style="color: #800080;">$badKey</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800000;">&quot;HKLM:\Software\CRTCORP\Product_B&quot;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\Users\cars<span style="color: pink;">&gt;</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$badKey</span>.GetValueNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: pink;">&gt;&gt;</span> <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;$value | &quot;</span> <span style="color: #008080; font-style: italic;">-nonewline</span><br />
<span style="color: pink;">&gt;&gt;</span>Write<span style="color: pink;">-</span>Host <span style="color: #800080;">$badKey</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;$value&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: pink;">&gt;&gt;</span> <span style="color: #000000;">&#125;</span><br />
<span style="color: pink;">&gt;&gt;</span><br />
PerfCtr1 <span style="color: pink;">|</span> <span style="color: #804000;">0</span> <span style="color: #804000;">0</span> <span style="color: #804000;">0</span> <span style="color: #804000;">0</span><br />
PerfCtr2 <span style="color: pink;">|</span> <span style="color: #804000;">0</span> <span style="color: #804000;">13</span> <span style="color: #804000;">136</span> <span style="color: #804000;">8</span><br />
PerfCtr3 <span style="color: pink;">|</span> <span style="color: #804000;">0</span> <span style="color: #804000;">0</span> <span style="color: #804000;">3</span> <span style="color: #804000;">101</span><br />
<br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\Users\cars<span style="color: pink;">&gt;</span> <span style="color: #800080;">$example</span><span style="color: pink;">=</span><span style="color: #800080;">$badKey</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;PerfCtr1&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\Users\cars<span style="color: pink;">&gt;</span> <span style="color: #800080;">$example</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">gm</span><br />
<br />
TypeName: System.Byte<br />
<br />
Name MemberType Definition<br />
<span style="color: pink;">----</span> <span style="color: pink;">----------</span> <span style="color: pink;">----------</span><br />
CompareTo Method System.Int32 CompareTo<span style="color: #000000;">&#40;</span>Object value<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> System.Int32 CompareTo<span style="color: #000000;">&#40;</span>Byte value<span style="color: #000000;">&#41;</span><br />
Equals Method System.Boolean Equals<span style="color: #000000;">&#40;</span>Object obj<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> System.Boolean Equals<span style="color: #000000;">&#40;</span>Byte obj<span style="color: #000000;">&#41;</span><br />
GetHashCode Method System.Int32 GetHashCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
GetType Method System.<span style="color: #008080; font-weight: bold;">Type</span> GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
GetTypeCode Method System.TypeCode GetTypeCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
ToString Method System.String ToString<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> System.String ToString<span style="color: #000000;">&#40;</span>String format<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> System.String ...</div></div>
<p>So what it it turns out I was getting from the GetValue method was a sequence of 4 bytes as an array.  This made me wonder what the heck was going on so I fired up RegEdit to take a look.  The contents of the Data column looked okay but the Type was different, so I expanded the column to see what was different and discovered REG_DWORD_BIG_ENDIAN as a type. This was one I don&#8217;t recall having seen before.</p>
<p>TechNet has the following to say about DWORD and it&#8217;s brethren:</p>
<p>REG_DWORD<br />
A 32-bit (4-byte) number. Boolean (&#8220;True&#8221; or &#8220;False&#8221;) values and many entries for device drivers and services use this data type. REG_DWORD data can be displayed and entered in hexadecimal or decimal format in the registry editor Regedit.exe. For an example, see the ActivityLogFlag entry.</p>
<p>REG_DWORD_BIG_ENDIAN<br />
Same as REG_DWORD. A 32-bit number in which the most significant byte is displayed as the leftmost (or high-order) byte. This is the most common format for storing numbers in computers that are running Windows Server 2003.</p>
<p>REG_DWORD_LITTLE_ENDIAN<br />
A 32-bit number in which the most significant byte is displayed as the rightmost (or low-order) byte. This is opposite of the order in which bytes are stored in the REG_DWORD and REG_DWORD_BIG_ENDIAN data types.</p>
<p>If you&#8217;re not paying attention it could be easy to miss the difference when using RegEedit since they appear almost identical to DWORD values.  The only obvious difference is the &#8220;Type&#8221; field.</p>
<p>So in the example above GetValue returns different values for &#8220;PerfCtr2&#8243; and &#8220;PerfCtr2 DWORD&#8221; which are nominally the same value (at least according to RegEdit).</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>Write<span style="color: pink;">-</span>Host <span style="color: #800080;">$key</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;PerfCtr2&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #804000;">0</span> <span style="color: #804000;">13</span> <span style="color: #804000;">136</span> <span style="color: #804000;">8</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>Write<span style="color: pink;">-</span>Host <span style="color: #800080;">$key</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;PerfCtr2 DWORD&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #804000;">886792</span></div></div>
<p>To help me figure out how to get the info I was looking for I put together a test and created a couple of dummy registry keys with each of the types of reg keys and some examples.</p>
<p>If we try to see what Powershell tells us about each of these keys we see that for our BIG_ENDIAN friend GetValueKind returns &#8220;unknown.&#8221;</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$key1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800000;">&quot;HKLM:\Software\CRTCORP\Product_A&quot;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>foreach <span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$key1</span>.GetValueNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$value</span> <span style="color: #800000;">&quot; | &quot;</span> <span style="color: #800080;">$key1</span>.GetValueKind<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #800000;">&quot;|&quot;</span> <span style="color: #800080;">$key1</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><br />
REG_SZ Example <span style="color: pink;">|</span> String <span style="color: pink;">|</span> This is a test of the emergency broadcast system<br />
REG_DWORD Example <span style="color: pink;">|</span> DWord <span style="color: pink;">|</span> <span style="color: #804000;">1</span><br />
REG_MULTI_SZ Example <span style="color: pink;">|</span> MultiString <span style="color: pink;">|</span> This is a test This is another Test<br />
REG_EXPAND_SZ <span style="color: pink;">|</span> ExpandString <span style="color: pink;">|</span> C:\ProgramData\Fred<br />
REG_DWORD_BIG_ENDIAN <span style="color: pink;">|</span> Unknown <span style="color: pink;">|</span> <span style="color: #804000;">161</span> <span style="color: #804000;">178</span> <span style="color: #804000;">195</span> <span style="color: #804000;">212</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span></div></div>
<p>GetValue converts each byte to a decimal value. Our key REG_DWORD_BIG_ENDIAN (0xa1b2c3d4) can be expressed as 4 bytes &#8220;a1&#8243; &#8220;b2&#8243; &#8220;c3&#8243; &#8220;d4&#8243; which when converted become the values &#8220;161&#8243; &#8220;178&#8243; &#8220;195&#8243; &#8220;212&#8243;. While this is mildly useful it doesn&#8217;t help us easily get the value we want 2712847316.   While it is possible to get the right value by doing some math [ (byte1 * 256^3) + (byte2 * 256^2) + (byte3 * 256) + byte4 ] I thought my resulting attempts to write a snippet to do this were ugly since it doesn&#8217;t appear Powershell has any easy way to do exponentiation.</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$key</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800000;">&quot;HKLM:\Software\CRTCorp\Product_A&quot;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$bytes</span><span style="color: pink;">=</span> <span style="color: #800080;">$key</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;REG_DWORD_BIG_ENDIAN&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$number</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>for <span style="color: #000000;">&#40;</span><span style="color: #800080;">$idx</span><span style="color: pink;">=</span><span style="color: #804000;">0</span>;$idx <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$bytes</span>.length;$idx<span style="color: pink;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: pink;">&gt;&gt;</span> <span style="color: #800080;">$pwr</span> <span style="color: pink;">=</span> <span style="color: #800080;">$bytes</span>.length<span style="color: pink;">-</span><span style="color: #800080;">$idx</span><span style="color: pink;">-</span><span style="color: #804000;">1</span>;<br />
<span style="color: pink;">&gt;&gt;</span> <span style="color: #800080;">$number</span><span style="color: pink;">+=</span> <span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$idx</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #000000;">&#91;</span>math<span style="color: #000000;">&#93;</span>::pow<span style="color: #000000;">&#40;</span><span style="color: #804000;">256</span><span style="color: pink;">,</span><span style="color: #800080;">$pwr</span><span style="color: #000000;">&#41;</span><br />
<span style="color: pink;">&gt;&gt;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: pink;">&gt;&gt;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>Write<span style="color: pink;">-</span>Host <span style="color: #800000;">&quot;The Value via method 1 is [$number]&quot;</span><br />
The Value via method <span style="color: #804000;">1</span> is <span style="color: #000000;">&#91;</span><span style="color: #804000;">2712847316</span><span style="color: #000000;">&#93;</span><br />
<br />
The second version uses the Math::Pow method to <span style="color: #0000FF;">do</span> help <span style="color: #0000FF;">do</span> the exponentiation:<span style="color: #000000;">&#40;</span>byte1 <span style="color: pink;">*</span> <span style="color: #804000;">256</span>^<span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span>byte2 <span style="color: pink;">*</span> <span style="color: #804000;">256</span>^<span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span>byte3 <span style="color: pink;">*</span> <span style="color: #804000;">256</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> byte4<br />
<span style="color: #000000;">&#91;</span>cc lang<span style="color: pink;">=</span><span style="color: #800000;">&quot;powershell&quot;</span> tab_size<span style="color: pink;">=</span><span style="color: #800000;">&quot;3&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$key</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800000;">&quot;HKLM:\Software\CRTCorp\Product_A&quot;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$bytes</span><span style="color: pink;">=</span> <span style="color: #800080;">$key</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;REG_DWORD_BIG_ENDIAN&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$number</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$number</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::pow<span style="color: #000000;">&#40;</span><span style="color: #804000;">256</span><span style="color: pink;">,</span><span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Pow<span style="color: #000000;">&#40;</span><span style="color: #804000;">256</span><span style="color: pink;">,</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #804000;">256</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">3</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>Write<span style="color: pink;">-</span>Host <span style="color: #800000;">&quot;The Value via Method 2 is [$number]&quot;</span><br />
The Value via method <span style="color: #804000;">3</span> is <span style="color: #000000;">&#91;</span><span style="color: #804000;">2712847316</span><span style="color: #000000;">&#93;</span></div></div>
<p>The third method was to write out the formula a little more explicitly so that (byte1 * 256^3) + (byte2 * 256^2) + (byte3 * 256^1) + (byte4 *256^0) becomes (byte1 * 16777216) + (byte2 * 65536) + (byte3 * 256) + byte4</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$key</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800000;">&quot;HKLM:\Software\CRTCorp\Product_A&quot;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$bytes</span><span style="color: pink;">=</span> <span style="color: #800080;">$key</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;REG_DWORD_BIG_ENDIAN&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$number</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span><span style="color: #800080;">$number</span><span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #804000;">16777216</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #804000;">65536</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">*</span> <span style="color: #804000;">256</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$bytes</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">3</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>Write<span style="color: pink;">-</span>Host <span style="color: #800000;">&quot;The Value via method 3 is [$number]&quot;</span><br />
The Value via method <span style="color: #804000;">3</span> is <span style="color: #000000;">&#91;</span><span style="color: #804000;">2712847316</span><span style="color: #000000;">&#93;</span></div></div>
<p>I was curious though as to why it was we could get the individual bytes converted but there wasn&#8217;t (to me) an obvious way to do the whole value. I came across a mention of the Convert Class on MSDN which does make it possible. Convert class in the .Net framework. After playing around some I was able to come up with a different way using the Convert Class that to me seems a little cleaner. The Convert class has several overloaded methods. One version of the ToInt64 method converts a string version of a number into 64-bit signed integer. Either this or ToUInt32 will work for our purposes here. ToInt32 won&#8217;t work because of the value may incorrectly (for our purposed) return a negative (i.e. signed) integer. The call to the ToInt64 method  requires an argument that specifies the base of the number the string represents (in this case hex= base 16).  So in theory that would work if we were able to represent the bytes as a hex string.. i.e. 0xA1B2C3D4.  That&#8217;s when I came across a VBScript to Powershell page describing converting numbers from decimal to hex that helped fill in the missing piece. Putting these two things together I was able to come up with a function to use in my script which seemed to work.</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">#############################################################################</span><br />
<span style="color: #008000;">#Convert a Reg_DWORD_BIG_ENDIAN value to a number that makes sense to a human</span><br />
<span style="color: #008000;"># $convertee should be a byte array</span><br />
<span style="color: #008000;">#--------------------------------------------</span><br />
<span style="color: #0000FF;">function</span> Convert<span style="color: pink;">-</span>RBEToDecimal<span style="color: #000000;">&#40;</span><span style="color: #800080;">$convertee</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<span style="color: #800080;">$tmpString</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;0x&quot;</span><br />
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$byte</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$convertee</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<span style="color: #800080;">$tmpString</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;{0:X}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$byte</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">Return</span> <span style="color: #000000;">&#91;</span>Convert<span style="color: #000000;">&#93;</span>::ToInt64<span style="color: #000000;">&#40;</span><span style="color: #800080;">$tmpString</span><span style="color: pink;">,</span><span style="color: #804000;">16</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #008000;">#############################################################################</span></div></div>
<p>The operative word here was &#8220;seemed&#8221;. I noticed in testing that there were instances where I got a very wrong answer.  As an example if the Registry value were (0xA102C4D4, or 2701312980 decimal) the function would return.  169001940 decimal as the value&#8230;I realized that in building $tmpString if the value of a particular byte was less than 16 it&#8217;d spit out a single character   0xC rather than 0x0C. This was fine if I was interested in the value of a single byte but when concatenating the values together makes for a big difference in the resulting value as 0xA102C3D4 would become 0xA12C3D4. The resolution for this was to change the format string to pad the value with a leading 0 if necessary. So $tmpString += &#8220;{0:X}&#8221; -f $byte  became $tmpString += &#8220;{0:X2}&#8221; -f $byte.<br />
So the final function I ended up using looks like this:</p>
<div class="codecolorer-container powershell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">############################################################################</span><br />
<span style="color: #008000;">#Convert a Reg_DWORD_BIG_ENDIAN value to a number that makes sense to a human</span><br />
<span style="color: #008000;"># $convertee should be a byte array</span><br />
<span style="color: #008000;">#--------------------------------------------</span><br />
<span style="color: #0000FF;">function</span> Convert<span style="color: pink;">-</span>RBEToDecimal<span style="color: #000000;">&#40;</span><span style="color: #800080;">$convertee</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<span style="color: #800080;">$tmpString</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;0x&quot;</span><br />
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$byte</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$convertee</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<span style="color: #800080;">$tmpString</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;{0:X2}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$byte</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">Return</span> <span style="color: #000000;">&#91;</span>Convert<span style="color: #000000;">&#93;</span>::ToInt64<span style="color: #000000;">&#40;</span><span style="color: #800080;">$tmpString</span><span style="color: pink;">,</span><span style="color: #804000;">16</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #008000;">###############################################################################</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://cars.lostroncos.org/2009/03/09/big_endian-registry-values/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

