<?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>Helyar.net</title>
	<atom:link href="http://www.helyar.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.helyar.net</link>
	<description>From the desktop of George Helyar</description>
	<lastBuildDate>Sat, 12 May 2012 01:24:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SQL Server random unique identifiers</title>
		<link>http://www.helyar.net/2012/sql-server-random-unique-identifiers/</link>
		<comments>http://www.helyar.net/2012/sql-server-random-unique-identifiers/#comments</comments>
		<pubDate>Fri, 04 May 2012 15:10:55 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=704</guid>
		<description><![CDATA[A common method of producing random unique identifiers in SQL server is by using a GUID field, calling newid() to generate the data. For the most part, this works because it&#8217;s 128 bits worth of random data, which means there is a very low probability of duplicate records for most databases. However, it is also [...]]]></description>
			<content:encoded><![CDATA[<p>A common method of producing random unique identifiers in SQL server is by using a GUID field, calling <code>newid()</code> to generate the data. For the most part, this works because it&#8217;s 128 bits worth of random data, which means there is a very low probability of duplicate records for most databases.</p>
<p>However, it is also common to combine this with the <code>checksum()</code> function to reduce it to a 32 bit integer. This makes collisions much more likely, even in relatively small databases. For example, the GUIDs <code>28258F69-6536-4198-BE37-94960ABF054F</code> and <code>49B60D4B-DC4A-4E18-825E-B4C99713D011</code> both checksum to <code>0xC3AD13D3</code>. With a table of about 100,000 rows collisions will start to occur more frequently by the <a href="http://en.wikipedia.org/wiki/Birthday_problem">birthday paradox</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: black;"><span style="color: #ff7700;font-weight:bold;color: blue;">def</span> P<span style="color: black;color: black;">&#40;</span>x, n<span style="color: black;color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;color: blue;">return</span> <span style="color: #ff4500;color: maroon;">1</span> - <span style="color: black;color: black;">&#40;</span><span style="color: black;color: black;">&#40;</span>x-<span style="color: #ff4500;color: maroon;">1</span><span style="color: black;color: black;">&#41;</span>/x<span style="color: black;color: black;">&#41;</span><span style="color: #66cc66;color: black;">**</span><span style="color: black;color: black;">&#40;</span>n <span style="color: #66cc66;color: black;">*</span> <span style="color: black;color: black;">&#40;</span>n-<span style="color: #ff4500;color: maroon;">1</span><span style="color: black;color: black;">&#41;</span>/<span style="color: #ff4500;color: maroon;">2</span><span style="color: black;color: black;">&#41;</span>
&nbsp;
<span style="color: #66cc66;color: black;">&gt;&gt;&gt;</span> P<span style="color: black;color: black;">&#40;</span><span style="color: #ff4500;color: maroon;">2</span><span style="color: #66cc66;color: black;">**</span><span style="color: #ff4500;color: maroon;">32</span>,<span style="color: #ff4500;color: maroon;">77500</span><span style="color: black;color: black;">&#41;</span>
<span style="color: #ff4500;color: maroon;">0.503022489601693</span>
&nbsp;
<span style="color: #66cc66;color: black;">&gt;&gt;&gt;</span> P<span style="color: black;color: black;">&#40;</span><span style="color: #ff4500;color: maroon;">2</span><span style="color: #66cc66;color: black;">**</span><span style="color: #ff4500;color: maroon;">32</span>,<span style="color: #ff4500;color: maroon;">200000</span><span style="color: black;color: black;">&#41;</span>
<span style="color: #ff4500;color: maroon;">0.9905011979711653</span>
&nbsp;
<span style="color: #66cc66;color: black;">&gt;&gt;&gt;</span> P<span style="color: black;color: black;">&#40;</span><span style="color: #ff4500;color: maroon;">2</span><span style="color: #66cc66;color: black;">**</span><span style="color: #ff4500;color: maroon;">52</span>,<span style="color: #ff4500;color: maroon;">100000000</span><span style="color: black;color: black;">&#41;</span>
<span style="color: #ff4500;color: maroon;">0.6705145268350288</span></pre></div></div>

<p>Using this maths, we can see that using a 32 bit random number, the probability of getting at least one collision is 50% at around 77,500 rows and 99% at 200,000 rows. We can also see that if we increase this to a 52 bit number, 100 million rows gives a 67% chance of getting at least one collision, so 64 bit should be plenty.</p>
<p>A compromise of both is to simply truncate the GUID at 64 bits and optionally convert to a <code>bigint</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;color: black;"><span style="color: #993333; font-weight: bold;color: blue;">SELECT</span> <span style="color: #993333; font-weight: bold;color: blue;">CONVERT</span><span style="color: #66cc66;color: black;">&#40;</span><span style="color: #993333; font-weight: bold;color: blue;">BIGINT</span><span style="color: #66cc66;color: black;">,</span> <span style="color: #993333; font-weight: bold;color: blue;">CONVERT</span><span style="color: #66cc66;color: black;">&#40;</span><span style="color: #993333; font-weight: bold;color: blue;">BINARY</span><span style="color: #66cc66;color: black;">&#40;</span><span style="color: #cc66cc;color: maroon;">8</span><span style="color: #66cc66;color: black;">&#41;</span><span style="color: #66cc66;color: black;">,</span> newid<span style="color: #66cc66;color: black;">&#40;</span><span style="color: #66cc66;color: black;">&#41;</span><span style="color: #66cc66;color: black;">&#41;</span><span style="color: #66cc66;color: black;">&#41;</span></pre></div></div>

<p>If you leave it as binary and don&#8217;t need to convert to an integer type, this does not have to be 8 bytes. For example, you could have a 5 or a 10 byte code.</p>
<p>None of these are perfect but the probability of a collision decreases with more bits. If 128 bit is too long for you (e.g. to display to users) but 32 bit generates too many collisions, try a compromise such as 64 bit.</p>
<p>If you are consistent enough, you may even be able to store the original GUID and just display the truncated form, which could allow you to change the length displayed later without changing the probability of collisions. This is more flexible but may lead to confusion among users and consistency is required (differing lengths could lead to bugs).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2012/sql-server-random-unique-identifiers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YouTube</title>
		<link>http://www.helyar.net/2012/youtube/</link>
		<comments>http://www.helyar.net/2012/youtube/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 20:27:56 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=687</guid>
		<description><![CDATA[Suggestion for YouTube: Put the green and red like/dislike bar on the thumbnail of the video so you can see if a video is going to be any good before you visit it and to reduce mindless spam from misleading video names and thumbnails. Possibly the best improvement to YouTube usability since the advent of [...]]]></description>
			<content:encoded><![CDATA[<p>Suggestion for YouTube:</p>
<p>Put the green and red like/dislike bar on the thumbnail of the video so you can see if a video is going to be any good before you visit it and to reduce mindless spam from misleading video names and thumbnails.</p>
<p>Possibly the best improvement to YouTube usability since the advent of the play button.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2012/youtube/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster than light neutrinos</title>
		<link>http://www.helyar.net/2011/faster-than-light-neutrinos/</link>
		<comments>http://www.helyar.net/2011/faster-than-light-neutrinos/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 13:32:52 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=677</guid>
		<description><![CDATA[OK so this is probably going to demonstrate how bad I am at physics, and I will probably be flamed for being an idiot, but here are some of my thoughts on the faster than light neutrinos. Time slows down as you approach the speed of light. Velocity is a derivation of time (speed = [...]]]></description>
			<content:encoded><![CDATA[<p>OK so this is probably going to demonstrate how bad I am at physics, and I will probably be flamed for being an idiot, but here are some of my thoughts on the faster than light neutrinos.</p>
<ol>
<li>Time slows down as you approach the speed of light. Velocity is a derivation of time (speed = distance / time). This can make it difficult to measure, and the time dilation needs to be accounted for.</li>
<li>When measuring things close to the speed of light, the equipment itself has the same limitations. It takes time for a signal to get from one part of the equipment to another.</li>
<li>The Earth itself is moving in the solar system, the solar system is moving in the galaxy, and the galaxy is moving in the universe. The speed of light is an absolute limit, but the measurement of something moving between two points on Earth is a relative measurement. If something was fixed in an absolute position, it would be moving very quickly relative to the Earth.</li>
<li>The speed of light limitation applies to objects with mass. The mass of neutrinos is believed to be non-zero, but is not yet completely known, and objects with energy essentially have more mass, so the mass of it changes as it accelerates. It&#8217;s hard to do maths when you don&#8217;t have all of the starting variables.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/faster-than-light-neutrinos/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Buyer beware: (low cost) 6 Gbps SATA III cards are a scam.</title>
		<link>http://www.helyar.net/2011/buyer-beware-6-gbps-sata-iii-cards-are-a-scam/</link>
		<comments>http://www.helyar.net/2011/buyer-beware-6-gbps-sata-iii-cards-are-a-scam/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 18:01:01 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[sata]]></category>
		<category><![CDATA[scam]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=665</guid>
		<description><![CDATA[I recently upgraded to a new SSD, the OCZ Agility 3. It gave really good speeds, but I couldn&#8217;t help but feel that I was limiting it by putting it in a motherboard which only had 3 Gbps SATA II ports. I bought a Lycom PE115 6Gbps SATA III adapter, and put it in a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently upgraded to a new SSD, the <a href="http://www.ocztechnology.com/ocz-agility-3-sata-iii-2-5-ssd.html">OCZ Agility 3</a>. It gave really good speeds, but I couldn&#8217;t help but feel that I was limiting it by putting it in a <a href="http://www.supermicro.com/products/motherboard/QPI/5500/X8DAL-i.cfm">motherboard</a> which only had 3 Gbps SATA II ports.</p>
<p>I bought a <a href="http://www.lycom.com.tw/PE115.htm">Lycom PE115</a> 6Gbps SATA III adapter, and put it in a PCIe 2.0 port, but when I benchmarked the drive with <a href="http://crystalmark.info/software/CrystalDiskMark/index-e.html">CrystalDiskMark</a>, on an idle Windows 7 x64 machine (Dual Xeon E5620, 8GiB ECC-R 1333MHz) the results were very disappointing.</p>
<p>Not only was there no improvement over the port on the motherboard, the dedicated 6Gbps SATA III card was actually significantly slower than the 3 Gbps SATA II port (roughly 64% of the speed).</p>
<p>I tried without and then with the drivers for the card installed, and it made no real difference.</p>
<div id="attachment_667" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.helyar.net/wp-content/uploads/2011/10/sata6_scam_1.png"><img src="http://www.helyar.net/wp-content/uploads/2011/10/sata6_scam_1.png" alt="" title="sata6_scam_1" width="640" height="480" class="size-full wp-image-667" /></a><p class="wp-caption-text">Fill 0</p></div>
<p>The blue bar is on the motherboard&#8217;s SATA 3Gbps.<br />
The red bar is on the PE115&#8242;s SATA 6Gbps<br />
The yellow bar is the PE115 with drivers manually installed.<br />
The green bar is back on the motherboard, to confirm it.</p>
<p>The results show that the PE115 consistently performs significantly worse than the motherboard in both fill 0&#215;00 (above) and fill random (below) operations.</p>
<div id="attachment_668" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.helyar.net/wp-content/uploads/2011/10/sata6_scam_2.png"><img src="http://www.helyar.net/wp-content/uploads/2011/10/sata6_scam_2.png" alt="" title="sata6_scam_2" width="640" height="480" class="size-full wp-image-668" /></a><p class="wp-caption-text">Fill Random</p></div>
<p>All of this was done in CrystalDiskMark 3.0.1 x64.</p>
<p><a href="http://www.helyar.net/wp-content/uploads/2011/10/back_to_original_00.png"><img src="http://www.helyar.net/wp-content/uploads/2011/10/back_to_original_00.png" alt="" title="back_to_original_00" width="416" height="378" class="aligncenter size-full wp-image-672" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/buyer-beware-6-gbps-sata-iii-cards-are-a-scam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 8 is the next Vista fail.</title>
		<link>http://www.helyar.net/2011/windows-8-is-the-next-vista-fail/</link>
		<comments>http://www.helyar.net/2011/windows-8-is-the-next-vista-fail/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 11:21:30 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=655</guid>
		<description><![CDATA[I&#8217;m calling it now. First Windows ME, then Vista, next 8. All failures, or soon to be. There&#8217;s nothing new in Windows 8 that warrants replacing Windows 7 so soon but there&#8217;s enough changed on the surface to piss people off. People don&#8217;t like having changes forced upon them (see also: Facebook). The only people [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m calling it now. First Windows ME, then Vista, next 8. All failures, or soon to be.</p>
<p>There&#8217;s nothing new in Windows 8 that warrants replacing Windows 7 so soon but there&#8217;s enough changed on the surface to piss people off. People don&#8217;t like having changes forced upon them (see also: Facebook). The only people that will be getting Windows 8 will be people who got it pre-installed and had no choice, and I don&#8217;t see any businesses upgrading to Windows 8 whatsoever.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/windows-8-is-the-next-vista-fail/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Concise glossary of reverse engineering</title>
		<link>http://www.helyar.net/2011/concise-glossary-of-reverse-engineering/</link>
		<comments>http://www.helyar.net/2011/concise-glossary-of-reverse-engineering/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 14:28:39 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[hack]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=652</guid>
		<description><![CDATA[Debugger Executes a program, displaying the memory as it runs. Decompiler Converts object code to a higher level language, such as C. Disassembler Converts object code to assembly. Stupid Charging thousands of dollars for software whose target audience primarily use it to crack software rather than paying for it.]]></description>
			<content:encoded><![CDATA[<p><strong>Debugger</strong><br />
Executes a program, displaying the memory as it runs.</p>
<p><strong>Decompiler</strong><br />
Converts object code to a higher level language, such as C.</p>
<p><strong>Disassembler</strong><br />
Converts object code to assembly.</p>
<p><strong>Stupid</strong><br />
Charging thousands of dollars for software whose target audience primarily use it to crack software rather than paying for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/concise-glossary-of-reverse-engineering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Icy backplanes</title>
		<link>http://www.helyar.net/2011/icy-backplanes/</link>
		<comments>http://www.helyar.net/2011/icy-backplanes/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 15:43:45 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[nas]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=640</guid>
		<description><![CDATA[I just realised that Icy Dock and Icy Box are not the same company.]]></description>
			<content:encoded><![CDATA[<p>I just realised that <a href="http://www.icydock.com/category.php?id=41">Icy Dock</a> and <a href="http://www.icybox.com.tw/page/backplane_system/backplane_system.htm">Icy Box</a> are not the same company.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/icy-backplanes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop saying SEQUEL</title>
		<link>http://www.helyar.net/2011/stop-saying-sequel/</link>
		<comments>http://www.helyar.net/2011/stop-saying-sequel/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 12:47:51 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=633</guid>
		<description><![CDATA[SQL is not the same thing as SEQUEL. If you&#8217;re a grumpy old DBA, stuck in your ways, who actually used SEQUEL back in the 1970s, that&#8217;s fine. For all the new kids just getting into SQL, it&#8217;s pronounced es-que-el, not sequel. When you call it sequel, you sound like just as much of an [...]]]></description>
			<content:encoded><![CDATA[<p>SQL is not the same thing as SEQUEL. If you&#8217;re a grumpy old DBA, stuck in your ways, who actually used SEQUEL back in the 1970s, that&#8217;s fine. For all the new kids just getting into SQL, it&#8217;s pronounced es-que-el, not sequel. When you call it sequel, you sound like just as much of an idiot as someone who says lynuks. It&#8217;s annoying.</p>
<p>The &#8220;SQL&#8221; pronunciation is actually defined in the original 1986 specification for SQL and confirmed by common DBMS such as <a href="http://dev.mysql.com/doc/refman/5.0/en/what-is-mysql.html">MySQL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/stop-saying-sequel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Studio &#8220;There was a problem sending the command to the program&#8221;</title>
		<link>http://www.helyar.net/2011/visual-studio-there-was-a-problem-sending-the-command-to-the-program/</link>
		<comments>http://www.helyar.net/2011/visual-studio-there-was-a-problem-sending-the-command-to-the-program/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 21:23:33 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=611</guid>
		<description><![CDATA[Since moving to Visual Studio 2010 on Windows 7 x64, I&#8217;ve been getting this error a lot. Every time I open Visual Studio by opening a file rather than running its executable directly, in fact. Most of the answers seem to revolve around running Visual Studio as a normal user rather than an administrator, but [...]]]></description>
			<content:encoded><![CDATA[<p>Since moving to Visual Studio 2010 on Windows 7 x64, I&#8217;ve been getting this error a lot. Every time I open Visual Studio by opening a file rather than running its executable directly, in fact.</p>
<p><a href="http://www.helyar.net/wp-content/uploads/2011/03/vserror.png"><img src="http://www.helyar.net/wp-content/uploads/2011/03/vserror.png" alt="" title="vserror" width="641" height="519" class="aligncenter size-full wp-image-617" /></a></p>
<p>Most of the answers seem to revolve around running Visual Studio as a normal user rather than an administrator, but I was already doing that.</p>
<p>Eventually, a reply to <a href="http://connect.microsoft.com/VisualStudio/feedback/details/601871/there-was-a-problem-sending-the-command-to-the-program">this bug</a> provided an answer.</p>
<p>When I checked the key, I saw</p>
<pre>[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\DDECache\VisualStudio.10.0\system]
"ProcessName"="devenv.exe"
"WindowName"="Visual Studio Application Management Window"
"WindowClassName"="VisualStudioAppManagement"</pre>
<p>Deleting the &#8220;system&#8221; key then opening a file again worked and replaced the key with working values</p>
<pre>[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\DDECache\VisualStudio.10.0\system]
"ProcessName"="devenv.exe"
"WindowName"="DDEHandler"
"WindowClassName"="DDEHandler"</pre>
<p>When it has the correct values (refresh to make sure that it does) remove &#8220;set&#8221; permissions from your own user so that it can&#8217;t replace them with the bad values, to make the change permanent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/visual-studio-there-was-a-problem-sending-the-command-to-the-program/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Set default command prompt directory</title>
		<link>http://www.helyar.net/2011/set-default-command-prompt-directory/</link>
		<comments>http://www.helyar.net/2011/set-default-command-prompt-directory/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 14:20:58 +0000</pubDate>
		<dc:creator>George Helyar</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.helyar.net/?p=605</guid>
		<description><![CDATA[It&#8217;s too difficult to set the default command prompt directory on Windows. I found several methods, none of which worked correctly. In particular, it is common for people to set a &#8220;cd /d path&#8221; in their AutoRun key in the registry but this breaks the power toy and Windows 7&#8242;s built in hold shift and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s too difficult to set the default command prompt directory on Windows. I found several methods, none of which worked correctly.</p>
<p>In particular, it is common for people to set a &#8220;cd /d path&#8221; in their AutoRun key in the registry but this breaks the power toy and Windows 7&#8242;s built in hold shift and right click on a directory to open a command prompt there. This can be worked around by adding a /d to the shell extension in the registry.</p>
<p>What doesn&#8217;t seem to be mentioned anywhere though is that this AutoRun key also gets run when you double click on a batch file. That means a batch file which assumes its own current directory (a reasonable assumption &#8211; more reasonable than using absolute paths) may not be able to find files in the same directory as it.</p>
<p>What I really wanted to do was move my home directory to my D: drive but the command prompt was still opening on the C:</p>
<p>Most people also seem to only change the default directory of their command prompt to match a non-default home directory.</p>
<p>The first mistake I made was to type &#8220;cmd&#8221; into the start menu and right click on it to pin it there. This calls it &#8220;Windows Command Processor&#8221; and starts in C:\Windows\System32 (because that&#8217;s where cmd.exe lives). Instead, go through the start menu programs list and find &#8220;Command Prompt&#8221; under &#8220;Accessories&#8221; and pin that. It will correctly default to your home directory, because the &#8220;start in&#8221; is set to <code>%HOMEDRIVE%%HOMEPATH%</code>. Note that you could just change this shortcut&#8217;s arguments (cmd /k cd &#8220;PATH&#8221;) or start in but it will only change it for that one shortcut.</p>
<p>Anyway, once you are using &#8220;Command Prompt&#8221;, set your home directory. I&#8217;m using Windows 7 Pro, so I can go to Computer Management and just set the directory for my user in the GUI under &#8220;Users and Groups&#8221;. This is no longer available in home versions of Windows (they shouldn&#8217;t have removed it) but you may still be able to set your home directory by using the command</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;color: black;">net user USERNAME /homedir:PATH</pre></div></div>

<p>where &#8220;USERNAME&#8221; is your user name and &#8220;PATH&#8221; is the directory you want to set. You can check this with the command <code>net user</code>.</p>
<p>When I type &#8220;cmd&#8221; into the run dialogue, it still opens on C: but at least batch files work now. Further suggestions are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helyar.net/2011/set-default-command-prompt-directory/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

