<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>VibrantCode - Tips</title>
    <link>http://blog.andrewnurse.net/</link>
    <description>Oooh...pretty code</description>
    <language>en-us</language>
    <copyright>Andrew Nurse</copyright>
    <lastBuildDate>Wed, 04 Mar 2009 17:43:24 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>andrew@andrewnurse.net</managingEditor>
    <webMaster>andrew@andrewnurse.net</webMaster>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=097ca941-0cda-4b30-906d-eb100045537c</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=097ca941-0cda-4b30-906d-eb100045537c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
My laptop is rapidly becoming obsolete, particularly when it comes to disk space :(. 
I want to install my games on it, so I have something to do <strike>in class </strike>between
classes, but I’m running out space.  So, I came up with an idea: Buy a 16GB USB
Key, and put a bunch of games on that!  I keep my USB keys in my backpack, so
they’re never too far away.  It sounded like the perfect solution, until I noticed
that many programs can’t be installed on Removable Drives!
</p>
        <p>
So, I came up with a simple workaround, once again using an awesome tool from Sysinternals
:).  I used <a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" target="_blank">Junction</a> to
create a junction folder called “C:\Program Files\Games” which points to a “Games”
folder on my USB Key.  The following command line does the trick (assuming F:\Games
is the folder on the USB key, and <strong>it already exists</strong>):
</p>
        <p>
junction.exe “C:\Program Files\Games” “F:\Games”
</p>
        <p>
Seems to be working so far!  I just install the game into that folder, and all
the files go to the USB Key.  Of course, its not quite the same as a <a href="http://portableapps.com/" target="_blank">portable
app</a>, since it will only run on the machine it was installed on, but it takes some
of the burden off of my hard drive.  If my laptop supported SDHC, I’d probably
use a 16GB SD card and just leave it plugged in to my laptop, but unfortunately, that’s
not an option.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=097ca941-0cda-4b30-906d-eb100045537c" />
      </body>
      <title>Tips and Tricks: Installing Programs to a USB Key</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/04/TipsAndTricksInstallingProgramsToAUSBKey.aspx</link>
      <pubDate>Wed, 04 Mar 2009 17:43:24 GMT</pubDate>
      <description>&lt;p&gt;
My laptop is rapidly becoming obsolete, particularly when it comes to disk space :(.&amp;#160;
I want to install my games on it, so I have something to do &lt;strike&gt;in class &lt;/strike&gt;between
classes, but I’m running out space.&amp;#160; So, I came up with an idea: Buy a 16GB USB
Key, and put a bunch of games on that!&amp;#160; I keep my USB keys in my backpack, so
they’re never too far away.&amp;#160; It sounded like the perfect solution, until I noticed
that many programs can’t be installed on Removable Drives!
&lt;/p&gt;
&lt;p&gt;
So, I came up with a simple workaround, once again using an awesome tool from Sysinternals
:).&amp;#160; I used &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" target="_blank"&gt;Junction&lt;/a&gt; to
create a junction folder called “C:\Program Files\Games” which points to a “Games”
folder on my USB Key.&amp;#160; The following command line does the trick (assuming F:\Games
is the folder on the USB key, and &lt;strong&gt;it already exists&lt;/strong&gt;):
&lt;/p&gt;
&lt;p&gt;
junction.exe “C:\Program Files\Games” “F:\Games”
&lt;/p&gt;
&lt;p&gt;
Seems to be working so far!&amp;#160; I just install the game into that folder, and all
the files go to the USB Key.&amp;#160; Of course, its not quite the same as a &lt;a href="http://portableapps.com/" target="_blank"&gt;portable
app&lt;/a&gt;, since it will only run on the machine it was installed on, but it takes some
of the burden off of my hard drive.&amp;#160; If my laptop supported SDHC, I’d probably
use a 16GB SD card and just leave it plugged in to my laptop, but unfortunately, that’s
not an option.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=097ca941-0cda-4b30-906d-eb100045537c" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</comments>
      <category>CMPT 376</category>
      <category>Tips</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=22986c28-2a06-4345-88d7-023d3b650a60</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,22986c28-2a06-4345-88d7-023d3b650a60.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,22986c28-2a06-4345-88d7-023d3b650a60.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=22986c28-2a06-4345-88d7-023d3b650a60</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Before I start this post, I need to say one thing: <a href="http://blogs.technet.com/markrussinovich/" target="_blank">Mark
Russinovich</a> (as well as anyone else who works on the <a href="http://technet.microsoft.com/en-ca/sysinternals/default.aspx" target="_blank">Sysinternals</a> stuff)
is a Windows Magician.  The stuff these tools can do is just plan magic :).
</p>
        <p>
Last week, my <a href="http://charlesnurse.com/" target="_blank">Dad</a>’s Dell XPS
laptop decided it was tired of rendering graphics and the video card just stopped
working (apparently this is a known issue).  Dell support was fairly helpful
and on Friday we received a box to sent the computer in for a motherboard replacement. 
Now, I’m paranoid when it comes to data, I don’t trust anyone.  So, I suggested
we try and wipe the hard drive of all the sensitive data on the machine, and change
the password so that we wouldn’t have to give Dell the actual password.  Now,
only the graphics card was damaged, the computer ran just fine and even the graphics
were intermittent (at first).  We tried to get the graphics card working long
enough to enable remote desktop, so we could connect from his screaming new Dell desktop
(Quad Core i7 with 12GB of RAM… I’m jealous).  Unfortunately, by that time, the
graphics card was done… no dice :(
</p>
        <p>
After a little searching, I came across some tips for enabling remote desktop… remotely. 
It turns out, there are a number of ways to connect to a machine and make changes
remotely!  The first tip I found was to use the remote registry to enable it: <a title="http://www.windowsdevcenter.com/pub/a/windows/2004/05/04/serverhacks_remote.html" href="http://www.windowsdevcenter.com/pub/a/windows/2004/05/04/serverhacks_remote.html">http://www.windowsdevcenter.com/pub/a/windows/2004/05/04/serverhacks_remote.html</a>. 
Unfortunately, the Remote Registry service wasn’t running on the laptop!  That’s
when I found Sysinternals “<a href="http://technet.microsoft.com/en-us/sysinternals/bb897542.aspx" target="_blank">PsService</a>”
tool.  The tool allows you, as long as you have the Admin account password, to
enable/disable and change the start mode of services on a remote machine.  So,
first I enabled to remote registry service
</p>
        <pre>psservice <a href="file://\\bilbo">\\bilbo</a> –u [UserName] start RemoteRegistry</pre>
        <p>
Then, just for good measure, I set the Remote Desktop service to autostart
</p>
        <pre>psservice <a href="file://\\bilbo">\\bilbo</a> –u [UserName] setconfig TermService
auto</pre>
        <p>
Finally, rather than fight with creating a firewall rule remotely, I just disabled
the Windows Firewall service (don’t do this unless you absolutely have to :D)
</p>
        <pre>psservice <a href="file://\\bilbo">\\bilbo</a> –u [UserName] setconfig MpsSvc
disabled</pre>
        <p>
(Btw, I got all these service names using the Services console on another machine)
</p>
        <p>
Finally, I followed the instructions I mentioned earlier to set the right registry
flags to allow Remote Desktop.  I killed the power to the PC (I actually tried
Sysinternals “<a href="http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx" target="_blank">PsShutdown</a>”
tool first, but had less luck getting that working :D) and restarted it.  When
I heard the Windows start up sound (as I said, the rest of the components worked just
fine :), I fired up remote desktop connection and… bam!  I had a remote desktop
screen.  After a quick pass over the data drive with yet another Sysinternals
tool: “<a href="http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx" target="_blank">SDelete</a>”
and a password change, we shut the computer down, packed it up and sent it off to
Dell, confident that the important data was scrubbed clean.
</p>
        <p>
Like I said… black magic :).  But seriously, the Sysinternals tools rock! 
If you don’t have them, <a href="http://technet.microsoft.com/en-us/sysinternals/0e18b180-9b7a-4c49-8120-c47c5a693683.aspx" target="_blank">get
them now</a>!
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=22986c28-2a06-4345-88d7-023d3b650a60" />
      </body>
      <title>Tips and Tricks: Remotely Enable Remote Desktop</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,22986c28-2a06-4345-88d7-023d3b650a60.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/02/23/TipsAndTricksRemotelyEnableRemoteDesktop.aspx</link>
      <pubDate>Mon, 23 Feb 2009 17:12:10 GMT</pubDate>
      <description>&lt;p&gt;
Before I start this post, I need to say one thing: &lt;a href="http://blogs.technet.com/markrussinovich/" target="_blank"&gt;Mark
Russinovich&lt;/a&gt; (as well as anyone else who works on the &lt;a href="http://technet.microsoft.com/en-ca/sysinternals/default.aspx" target="_blank"&gt;Sysinternals&lt;/a&gt; stuff)
is a Windows Magician.&amp;#160; The stuff these tools can do is just plan magic :).
&lt;/p&gt;
&lt;p&gt;
Last week, my &lt;a href="http://charlesnurse.com/" target="_blank"&gt;Dad&lt;/a&gt;’s Dell XPS
laptop decided it was tired of rendering graphics and the video card just stopped
working (apparently this is a known issue).&amp;#160; Dell support was fairly helpful
and on Friday we received a box to sent the computer in for a motherboard replacement.&amp;#160;
Now, I’m paranoid when it comes to data, I don’t trust anyone.&amp;#160; So, I suggested
we try and wipe the hard drive of all the sensitive data on the machine, and change
the password so that we wouldn’t have to give Dell the actual password.&amp;#160; Now,
only the graphics card was damaged, the computer ran just fine and even the graphics
were intermittent (at first).&amp;#160; We tried to get the graphics card working long
enough to enable remote desktop, so we could connect from his screaming new Dell desktop
(Quad Core i7 with 12GB of RAM… I’m jealous).&amp;#160; Unfortunately, by that time, the
graphics card was done… no dice :(
&lt;/p&gt;
&lt;p&gt;
After a little searching, I came across some tips for enabling remote desktop… remotely.&amp;#160;
It turns out, there are a number of ways to connect to a machine and make changes
remotely!&amp;#160; The first tip I found was to use the remote registry to enable it: &lt;a title="http://www.windowsdevcenter.com/pub/a/windows/2004/05/04/serverhacks_remote.html" href="http://www.windowsdevcenter.com/pub/a/windows/2004/05/04/serverhacks_remote.html"&gt;http://www.windowsdevcenter.com/pub/a/windows/2004/05/04/serverhacks_remote.html&lt;/a&gt;.&amp;#160;
Unfortunately, the Remote Registry service wasn’t running on the laptop!&amp;#160; That’s
when I found Sysinternals “&lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb897542.aspx" target="_blank"&gt;PsService&lt;/a&gt;”
tool.&amp;#160; The tool allows you, as long as you have the Admin account password, to
enable/disable and change the start mode of services on a remote machine.&amp;#160; So,
first I enabled to remote registry service
&lt;/p&gt;
&lt;pre&gt;psservice &lt;a href="file://\\bilbo"&gt;\\bilbo&lt;/a&gt; –u [UserName] start RemoteRegistry&lt;/pre&gt;
&lt;p&gt;
Then, just for good measure, I set the Remote Desktop service to autostart
&lt;/p&gt;
&lt;pre&gt;psservice &lt;a href="file://\\bilbo"&gt;\\bilbo&lt;/a&gt; –u [UserName] setconfig TermService
auto&lt;/pre&gt;
&lt;p&gt;
Finally, rather than fight with creating a firewall rule remotely, I just disabled
the Windows Firewall service (don’t do this unless you absolutely have to :D)
&lt;/p&gt;
&lt;pre&gt;psservice &lt;a href="file://\\bilbo"&gt;\\bilbo&lt;/a&gt; –u [UserName] setconfig MpsSvc
disabled&lt;/pre&gt;
&lt;p&gt;
(Btw, I got all these service names using the Services console on another machine)
&lt;/p&gt;
&lt;p&gt;
Finally, I followed the instructions I mentioned earlier to set the right registry
flags to allow Remote Desktop.&amp;#160; I killed the power to the PC (I actually tried
Sysinternals “&lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx" target="_blank"&gt;PsShutdown&lt;/a&gt;”
tool first, but had less luck getting that working :D) and restarted it.&amp;#160; When
I heard the Windows start up sound (as I said, the rest of the components worked just
fine :), I fired up remote desktop connection and… bam!&amp;#160; I had a remote desktop
screen.&amp;#160; After a quick pass over the data drive with yet another Sysinternals
tool: “&lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx" target="_blank"&gt;SDelete&lt;/a&gt;”
and a password change, we shut the computer down, packed it up and sent it off to
Dell, confident that the important data was scrubbed clean.
&lt;/p&gt;
&lt;p&gt;
Like I said… black magic :).&amp;#160; But seriously, the Sysinternals tools rock!&amp;#160;
If you don’t have them, &lt;a href="http://technet.microsoft.com/en-us/sysinternals/0e18b180-9b7a-4c49-8120-c47c5a693683.aspx" target="_blank"&gt;get
them now&lt;/a&gt;!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=22986c28-2a06-4345-88d7-023d3b650a60" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,22986c28-2a06-4345-88d7-023d3b650a60.aspx</comments>
      <category>Tips</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=3de21807-e19b-4541-a7d7-aadef6944140</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3de21807-e19b-4541-a7d7-aadef6944140</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently used the ‘yield’ keyword in a C# method and ran into a strange issue when
trying to verify arguments.  I always try to verify the arguments provided to
my methods so that I can throw <code>ArgumentException</code> or <code>ArgumentNullException</code> as
necessary.  However, when you use the ‘yield’ keyword to create an enumerator
in C#, you can run into issues
</p>
        <p>
The ‘yield’ keyword lets you easily create a method which returns an enumerator (which
can then be used in a <code>foreach</code> loop).  For example, if I wanted to
make a method that took a <code>DirectoryInfo</code> (representing a directory on
disk) and returned file names of all the .txt files in it, I would write this:
</p>
        <pre class="csharp" name="code">public IEnumerable&lt;string&gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException("dir");
    }
    foreach (FileInfo file in dir.GetFiles("*.txt")) {
        yield return file.Name;
    }
}</pre>
        <p>
However, the C# compiler will do something tricky with this method, because of the
'yield' keyword.  It will create a custom implementation of <code>IEnumerable&lt;string&gt;</code> class
that uses "magic" (I'm not going to go into detail as to how it works :P)
to jump in and out of the code you wrote. Then, it compiles our method to the following
(as decompiled with <a href="http://www.red-gate.com/products/reflector/" target="_blank">RedGate's
.Net Reflector</a>, a free tool every .Net developer <strong>must</strong> have :D):
</p>
        <pre class="csharp" name="code">public IEnumerable&lt;string&gt; GetTextFiles(DirectoryInfo dir)
{
    &lt;GetTextFiles&gt;d__0 d__ = new &lt;GetTextFiles&lt;d__0(-2);
    d__.&lt;&gt;4__this = this;
    d__.&lt;&gt;3__dir = dir;
    return d__;
}</pre>
        <p>
Wait a sec, where'd our code go?  It looks like it’s gone into this <code>&lt;GetTextFiles&gt;d__0</code> class. 
If you think that name sounds compiler-generated, you’re right!  It’s the custom
implementation of <code>IEnumerable&lt;string&gt;</code> that was created by the compiler. 
Cool, eh?  However, there’s a side effect here.  Where did our argument
checking code go?  Unless there’s something in the <code>&lt;GetTextFiles&gt;d__0</code> constructor,
the user could pass <code>null</code> in for the <code>dir</code> parameter and no
exception would be thrown!  So, let’s take a look at the <code>&lt;GetTextFiles&gt;d__0</code> constructor
(using Reflector again):
</p>
        <pre class="csharp" name="code">[DebuggerHidden]
public &lt;GetTextFiles&gt;d__0(int &lt;&gt;1__state)
{
    this.&lt;&gt;1__state = &lt;&gt;1__state;
    this.&lt;&gt;l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
}</pre>
        <p>
Nope, nothing there.  If you keep checking around the <code>&lt;GetTextFiles&gt;d__0</code> class,
you’ll find it in the <code>MoveNext</code> method on that class.  That means
that instead of checking the argument when you call the method, the argument won’t
be checked until the first time <code>MoveNext</code> is called (i.e. the first iteration
of a foreach loop).  If, instead, we wrap the actual “yield” code in it’s own
method, and call it from our original method (after argument checks), we’ll get the
desired result:
</p>
        <pre>public IEnumerable&lt;string&gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException("dir");
    }
    return InternalGetTextFiles(dir);
}
private IEnumerable&lt;string&gt; InternalGetTextFiles(DirectoryInfor dir) {
    foreach (FileInfo file in dir.GetFiles("*.txt")) {
        yield return file.Name;
    }
}</pre>
        <p>
Now, the "magic" is occurring in <code>InternalGetTextFiles</code> and <code>GetTextFiles</code> is
compiled without modification and our argument checking works just fine.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=3de21807-e19b-4541-a7d7-aadef6944140" />
      </body>
      <title>Argument check gotcha with &amp;lsquo;yield&amp;rsquo; keyword in C#</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/02/02/ArgumentCheckGotchaWithLsquoyieldrsquoKeywordInC.aspx</link>
      <pubDate>Mon, 02 Feb 2009 22:46:13 GMT</pubDate>
      <description>&lt;p&gt;
I recently used the ‘yield’ keyword in a C# method and ran into a strange issue when
trying to verify arguments.&amp;#160; I always try to verify the arguments provided to
my methods so that I can throw &lt;code&gt;ArgumentException&lt;/code&gt; or &lt;code&gt;ArgumentNullException&lt;/code&gt; as
necessary.&amp;#160; However, when you use the ‘yield’ keyword to create an enumerator
in C#, you can run into issues
&lt;/p&gt;
&lt;p&gt;
The ‘yield’ keyword lets you easily create a method which returns an enumerator (which
can then be used in a &lt;code&gt;foreach&lt;/code&gt; loop).&amp;#160; For example, if I wanted to
make a method that took a &lt;code&gt;DirectoryInfo&lt;/code&gt; (representing a directory on
disk) and returned file names of all the .txt files in it, I would write this:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public IEnumerable&amp;lt;string&amp;gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException(&amp;quot;dir&amp;quot;);
    }
    foreach (FileInfo file in dir.GetFiles(&amp;quot;*.txt&amp;quot;)) {
        yield return file.Name;
    }
}&lt;/pre&gt;
&lt;p&gt;
However, the C# compiler will do something tricky with this method, because of the
'yield' keyword.&amp;#160; It will create a custom implementation of &lt;code&gt;IEnumerable&amp;lt;string&amp;gt;&lt;/code&gt; class
that uses &amp;quot;magic&amp;quot; (I'm not going to go into detail as to how it works :P)
to jump in and out of the code you wrote. Then, it compiles our method to the following
(as decompiled with &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank"&gt;RedGate's
.Net Reflector&lt;/a&gt;, a free tool every .Net developer &lt;strong&gt;must&lt;/strong&gt; have :D):
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public IEnumerable&amp;lt;string&amp;gt; GetTextFiles(DirectoryInfo dir)
{
    &amp;lt;GetTextFiles&amp;gt;d__0 d__ = new &amp;lt;GetTextFiles&amp;lt;d__0(-2);
    d__.&amp;lt;&amp;gt;4__this = this;
    d__.&amp;lt;&amp;gt;3__dir = dir;
    return d__;
}&lt;/pre&gt;
&lt;p&gt;
Wait a sec, where'd our code go?&amp;#160; It looks like it’s gone into this &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; class.&amp;#160;
If you think that name sounds compiler-generated, you’re right!&amp;#160; It’s the custom
implementation of &lt;code&gt;IEnumerable&amp;lt;string&amp;gt;&lt;/code&gt; that was created by the compiler.&amp;#160;
Cool, eh?&amp;#160; However, there’s a side effect here.&amp;#160; Where did our argument
checking code go?&amp;#160; Unless there’s something in the &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; constructor,
the user could pass &lt;code&gt;null&lt;/code&gt; in for the &lt;code&gt;dir&lt;/code&gt; parameter and no
exception would be thrown!&amp;#160; So, let’s take a look at the &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; constructor
(using Reflector again):
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;[DebuggerHidden]
public &amp;lt;GetTextFiles&amp;gt;d__0(int &amp;lt;&amp;gt;1__state)
{
    this.&amp;lt;&amp;gt;1__state = &amp;lt;&amp;gt;1__state;
    this.&amp;lt;&amp;gt;l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
}&lt;/pre&gt;
&lt;p&gt;
Nope, nothing there.&amp;#160; If you keep checking around the &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; class,
you’ll find it in the &lt;code&gt;MoveNext&lt;/code&gt; method on that class.&amp;#160; That means
that instead of checking the argument when you call the method, the argument won’t
be checked until the first time &lt;code&gt;MoveNext&lt;/code&gt; is called (i.e. the first iteration
of a foreach loop).&amp;#160; If, instead, we wrap the actual “yield” code in it’s own
method, and call it from our original method (after argument checks), we’ll get the
desired result:
&lt;/p&gt;
&lt;pre&gt;public IEnumerable&amp;lt;string&amp;gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException(&amp;quot;dir&amp;quot;);
    }
    return InternalGetTextFiles(dir);
}
private IEnumerable&amp;lt;string&amp;gt; InternalGetTextFiles(DirectoryInfor dir) {
    foreach (FileInfo file in dir.GetFiles(&amp;quot;*.txt&amp;quot;)) {
        yield return file.Name;
    }
}&lt;/pre&gt;
&lt;p&gt;
Now, the &amp;quot;magic&amp;quot; is occurring in &lt;code&gt;InternalGetTextFiles&lt;/code&gt; and &lt;code&gt;GetTextFiles&lt;/code&gt; is
compiled without modification and our argument checking works just fine.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=3de21807-e19b-4541-a7d7-aadef6944140" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</comments>
      <category>CMPT 376</category>
      <category>Code Oddities</category>
      <category>Tips</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=c585caa9-c80a-48db-af4c-78ba85e07132</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c585caa9-c80a-48db-af4c-78ba85e07132</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the most common checks I do is a simple null check on arguments being passed
in to the methods I write.  I usually create a static class called “Arg” with
the following methods (to help out):
</p>
        <pre class="csharp" name="code">public static class Arg {
    public static void NotNull(object value, string paramName) {
        if (value == null) {
            throw new ArgumentNullException(paramName);
        }
    }
    public static void NotNullOrEmpty(string value, string paramName) {
        if (String.IsNullOrEmpty(value)) {
            // ED: Error_StringArgumentNullOrEmpty is a key in my Visual Studio
            //  project's default string resources file (Properties/Resources.resx)
            throw new ArgumentException(
                String.Format(CultureInfo.CurrentCulture, 
                              Resources.Error_StringArgumentNullOrEmpty, 
                              paramName), 
                paramName);
        }
    }
}</pre>
        <p>
Then, I can use it like this
</p>
        <pre class="csharp" name="code">public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(arg, "arg");
    Arg.NotNull(reallyLongArgumentName, "reallyLongArgumentName");
}</pre>
        <p>
I was recently playing with <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank">lambda
expressions</a> in C# and thought of a way to make this a little cooler.  The
result is, I can rewrite the lines above like this:
</p>
        <pre class="csharp" name="code">public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(() =&gt; arg);
    Arg.NotNull(() =&gt; reallyLongArgumentName);
}</pre>
        <p>
The first obvious advantage is that for longer argument names, its more concise. 
The second, is that I no longer have to worry about updating the strings representing
the parameter names when I rename arguments, the Visual Studio Refactoring engine
will take care of it for me.
</p>
        <p>
Obviously, this is slower than the previous method since I’m diving into the lambda
expression at runtime, but its cool.  But if I need the performance, I have a
little Regular Expression I can run in Visual Studio to convert the lambda calls back
to the string versions (and vice-versa)
</p>
        <p>
How does it work? Well, the core of the code is a static helper in the <code>Arg</code> class
</p>
        <pre class="csharp" name="code">private static string GetParameterName&lt;T&gt;(Expression&lt;Func&lt;T&gt;&gt; paramExpr) {
    LambdaExpression lambda = paramExpr as LambdaExpression;
    Debug.Assert(lambda != null);
    MemberExpression paramRef = lambda.Body as MemberExpression;
    Debug.Assert(paramRef != null);

    // Get the parameter name
    string paramName = paramRef.Member.Name;
    return paramName;
}</pre>
        <p>
Lines 2-5 dive through the Expression tree to find the <code>MemberExpression</code> that
represents the parameter (i.e. "foo" in <code>() =&gt; foo</code>). Then, we pull
out the <code>MemberInfo</code> for the parameter and check the name. With that method,
the actual checker is easy:
</p>
        <pre class="csharp" name="code">public static void NotNull(Expression&lt;Func&lt;object&gt;&gt; paramExpr) {
    string paramName = GetParameterName(paramExpr);

    // Compile the lambda (to get the value)
    Func&lt;object&gt; compiledLambda = paramExpr.Compile();
    
    // Run the contract check
    NotNull(compiledLambda(), paramName);
}</pre>
        <p>
Line 2 extracts the parameter name. Line 5 compiles the lambda into an actual function
that will return the value of the parameter. Finally, Line 8 uses the value and the
parameter name to call my original <code>object/string</code> version. The code for <code>NotNullOrEmpty</code> is
nearly identical.
</p>
        <p>
Anyway, if you're concerned about performance, stick to the overloads which take the
parameter name directly. I’ve attached the code as a TXT file, just rename to C#,
change the namespace as appropriate and enjoy
</p>
        <a href="http://blog.andrewnurse.net/content/binary/Arg.txt">Arg.txt (3.93 KB)</a>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=c585caa9-c80a-48db-af4c-78ba85e07132" />
      </body>
      <title>Wild Ideas &amp;ndash; Using lambdas to check arguments in C#</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/30/WildIdeasNdashUsingLambdasToCheckArgumentsInC.aspx</link>
      <pubDate>Fri, 30 Jan 2009 07:45:51 GMT</pubDate>
      <description>&lt;p&gt;
One of the most common checks I do is a simple null check on arguments being passed
in to the methods I write.&amp;nbsp; I usually create a static class called “Arg” with
the following methods (to help out):
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public static class Arg {
    public static void NotNull(object value, string paramName) {
        if (value == null) {
            throw new ArgumentNullException(paramName);
        }
    }
    public static void NotNullOrEmpty(string value, string paramName) {
        if (String.IsNullOrEmpty(value)) {
            // ED: Error_StringArgumentNullOrEmpty is a key in my Visual Studio
            //  project's default string resources file (Properties/Resources.resx)
            throw new ArgumentException(
                String.Format(CultureInfo.CurrentCulture, 
                              Resources.Error_StringArgumentNullOrEmpty, 
                              paramName), 
                paramName);
        }
    }
}&lt;/pre&gt;
&lt;p&gt;
Then, I can use it like this
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(arg, "arg");
    Arg.NotNull(reallyLongArgumentName, "reallyLongArgumentName");
}&lt;/pre&gt;
&lt;p&gt;
I was recently playing with &lt;a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank"&gt;lambda
expressions&lt;/a&gt; in C# and thought of a way to make this a little cooler.&amp;nbsp; The
result is, I can rewrite the lines above like this:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(() =&amp;gt; arg);
    Arg.NotNull(() =&amp;gt; reallyLongArgumentName);
}&lt;/pre&gt;
&lt;p&gt;
The first obvious advantage is that for longer argument names, its more concise.&amp;nbsp;
The second, is that I no longer have to worry about updating the strings representing
the parameter names when I rename arguments, the Visual Studio Refactoring engine
will take care of it for me.
&lt;/p&gt;
&lt;p&gt;
Obviously, this is slower than the previous method since I’m diving into the lambda
expression at runtime, but its cool.&amp;nbsp; But if I need the performance, I have a
little Regular Expression I can run in Visual Studio to convert the lambda calls back
to the string versions (and vice-versa)
&lt;/p&gt;
&lt;p&gt;
How does it work? Well, the core of the code is a static helper in the &lt;code&gt;Arg&lt;/code&gt; class
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;private static string GetParameterName&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T&amp;gt;&amp;gt; paramExpr) {
    LambdaExpression lambda = paramExpr as LambdaExpression;
    Debug.Assert(lambda != null);
    MemberExpression paramRef = lambda.Body as MemberExpression;
    Debug.Assert(paramRef != null);

    // Get the parameter name
    string paramName = paramRef.Member.Name;
    return paramName;
}&lt;/pre&gt;
&lt;p&gt;
Lines 2-5 dive through the Expression tree to find the &lt;code&gt;MemberExpression&lt;/code&gt; that
represents the parameter (i.e. "foo" in &lt;code&gt;() =&amp;gt; foo&lt;/code&gt;). Then, we pull
out the &lt;code&gt;MemberInfo&lt;/code&gt; for the parameter and check the name. With that method,
the actual checker is easy:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public static void NotNull(Expression&amp;lt;Func&amp;lt;object&amp;gt;&amp;gt; paramExpr) {
    string paramName = GetParameterName(paramExpr);

    // Compile the lambda (to get the value)
    Func&amp;lt;object&amp;gt; compiledLambda = paramExpr.Compile();
    
    // Run the contract check
    NotNull(compiledLambda(), paramName);
}&lt;/pre&gt;
&lt;p&gt;
Line 2 extracts the parameter name. Line 5 compiles the lambda into an actual function
that will return the value of the parameter. Finally, Line 8 uses the value and the
parameter name to call my original &lt;code&gt;object/string&lt;/code&gt; version. The code for &lt;code&gt;NotNullOrEmpty&lt;/code&gt; is
nearly identical.
&lt;/p&gt;
&lt;p&gt;
Anyway, if you're concerned about performance, stick to the overloads which take the
parameter name directly. I’ve attached the code as a TXT file, just rename to C#,
change the namespace as appropriate and enjoy
&lt;/p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/Arg.txt"&gt;Arg.txt (3.93 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=c585caa9-c80a-48db-af4c-78ba85e07132" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</comments>
      <category>CMPT 376</category>
      <category>Random Stuff</category>
      <category>Tips</category>
      <category>Wild Ideas</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=83aa617c-64ea-4bbe-83a9-4726763e95ef</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,83aa617c-64ea-4bbe-83a9-4726763e95ef.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,83aa617c-64ea-4bbe-83a9-4726763e95ef.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=83aa617c-64ea-4bbe-83a9-4726763e95ef</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As I mentioned in an earlier post about backing up a Zune Library (<a href="http://blog.andrewnurse.net/2008/12/11/BackingUpAZuneLibraryForWhenYouReinstallWindows.aspx" target="_blank">Backup
a Zune Library...</a>), I wanted to find a way to be able to actually store the Zune
library database on a different drive.  I played with the Microsoft Sysinternals
“<a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" target="_blank">Junction</a>”
tool, which lets you create <em>hardlinks</em> (<a href="http://en.wikipedia.org/wiki/Hard_Link" target="_blank">Wikipedia
on Hardlinks</a>) and managed to get it to work.  Here’s the process to do it
yourself.  Replace <em>UserName</em> with your Windows user name and <em>D:\Music\Zune\Library</em> with
the path to the folder you want to store the database in.
</p>
        <ol>
          <li>
Download Junction.exe from here: <a title="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx">http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx</a> (replace <em>D:\Utils\Sysinternals\junction.exe</em> below
with the path you downloaded junction.exe to) 
</li>
          <li>
Shut down the Zune software if it is running. 
</li>
          <li>
Rename the folder C:\Users\<em>UserName</em>\AppData\Local\Microsoft\Zune to Zune_backup
(just to be safe).  You may encounter a file locking issue, but I found that
if I waited a few minutes it worked. 
</li>
          <li>
Copy the Zune_backup folder to <em>D:\Music\Zune</em> and rename it to <em>Library</em></li>
          <li>
Run the following command: <pre>D:\Utils\Sysinternals\junction.exe Zune D:\Music\Zune\Library</pre></li>
        </ol>
        <p>
That should do it!  Start Zune up again and your library should be up and running. 
Now you should be able to reinstall the OS without having to back up the Zune library. 
I might try to whip up a PowerShell or Batch file to do this, but don’t get too hopeful
:).
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=83aa617c-64ea-4bbe-83a9-4726763e95ef" />
      </body>
      <title>Redirecting your Zune Library to another folder/drive</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,83aa617c-64ea-4bbe-83a9-4726763e95ef.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/11/RedirectingYourZuneLibraryToAnotherFolderdrive.aspx</link>
      <pubDate>Sun, 11 Jan 2009 06:53:55 GMT</pubDate>
      <description>&lt;p&gt;
As I mentioned in an earlier post about backing up a Zune Library (&lt;a href="http://blog.andrewnurse.net/2008/12/11/BackingUpAZuneLibraryForWhenYouReinstallWindows.aspx" target="_blank"&gt;Backup
a Zune Library...&lt;/a&gt;), I wanted to find a way to be able to actually store the Zune
library database on a different drive.&amp;#160; I played with the Microsoft Sysinternals
“&lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" target="_blank"&gt;Junction&lt;/a&gt;”
tool, which lets you create &lt;em&gt;hardlinks&lt;/em&gt; (&lt;a href="http://en.wikipedia.org/wiki/Hard_Link" target="_blank"&gt;Wikipedia
on Hardlinks&lt;/a&gt;) and managed to get it to work.&amp;#160; Here’s the process to do it
yourself.&amp;#160; Replace &lt;em&gt;UserName&lt;/em&gt; with your Windows user name and &lt;em&gt;D:\Music\Zune\Library&lt;/em&gt; with
the path to the folder you want to store the database in.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Download Junction.exe from here: &lt;a title="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx"&gt;http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx&lt;/a&gt; (replace &lt;em&gt;D:\Utils\Sysinternals\junction.exe&lt;/em&gt; below
with the path you downloaded junction.exe to) 
&lt;/li&gt;
&lt;li&gt;
Shut down the Zune software if it is running. 
&lt;/li&gt;
&lt;li&gt;
Rename the folder C:\Users\&lt;em&gt;UserName&lt;/em&gt;\AppData\Local\Microsoft\Zune to Zune_backup
(just to be safe).&amp;#160; You may encounter a file locking issue, but I found that
if I waited a few minutes it worked. 
&lt;/li&gt;
&lt;li&gt;
Copy the Zune_backup folder to &lt;em&gt;D:\Music\Zune&lt;/em&gt; and rename it to &lt;em&gt;Library&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
Run the following command: &lt;pre&gt;D:\Utils\Sysinternals\junction.exe Zune D:\Music\Zune\Library&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
That should do it!&amp;#160; Start Zune up again and your library should be up and running.&amp;#160;
Now you should be able to reinstall the OS without having to back up the Zune library.&amp;#160;
I might try to whip up a PowerShell or Batch file to do this, but don’t get too hopeful
:).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=83aa617c-64ea-4bbe-83a9-4726763e95ef" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,83aa617c-64ea-4bbe-83a9-4726763e95ef.aspx</comments>
      <category>Tips</category>
      <category>Zune</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=ec36b5af-6134-43b4-9cbd-8a74f3baeb54</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,ec36b5af-6134-43b4-9cbd-8a74f3baeb54.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,ec36b5af-6134-43b4-9cbd-8a74f3baeb54.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ec36b5af-6134-43b4-9cbd-8a74f3baeb54</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I regularly reinstall Windows, so when
I used iTunes, I had to make sure I knew how to back up my music library (because
I didn't want to re-rate all my songs :D).  I recently switched back to Zune
from iTunes because I got so frustrated with my cracked iPod Touch screen.  Then,
came the invevitable reinstall :)<br /><br />
I keep my music on a separate partition, along with ALL my data (Folder Redirection
for the win!), so the music files aren't the problem.  With iTunes I could place
the music library database on the other drive too, but so far no luck there with the
Zune software (I'm going to check out Junctions to see if that will work).  So,
I resigned myself to digging through my AppData folder to see if I could find the
stuff I needed.<br /><br />
For those who don't already know, the AppData folder, in Windows Vista is in: C:\Users\[UserName]\AppData. 
This is where programs (should) store their per-user settings and configuration data. 
Unfortunately (AFAIK) it's not possible to redirect this folder (like you can with
Documents, Music, etc.).  
<br /><br />
The Zune software stores its settings in C:\Users\[UserName]\AppData\Local\Microsoft\Zune. 
All I had to do was copy this folder over to my second partition, reinstall the OS
and reinstall the Zune software.  Then, I started the Zune software, just to
be sure and shut it down again.  I copied the backed up folder back into place,
restarted the Zune software and voila my library is back.  I was even able to
reconnect my Zune and have it automatically recognize it and sync!<br /><br />
So, in summary:<br /><ol><li>
Back up C:\Users\[UserName]\AppData\Local\Microsoft\Zune</li><li>
Reinstall Windows and other Apps<br /></li><li>
Reinstall Zune</li><li>
Start Zune software (not sure if it's necessary, but it worked for me)</li><li>
Shutdown Zune software</li><li>
Copy backup back in to C:\Users\[UserName]\AppData\Local\Microsoft\Zune</li><li>
Start Zune software and enjoy!</li></ol>
Let me know if that works for you, or if you have problems!<br /><p></p><img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=ec36b5af-6134-43b4-9cbd-8a74f3baeb54" /></body>
      <title>Backing up a Zune Library for when you reinstall Windows</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,ec36b5af-6134-43b4-9cbd-8a74f3baeb54.aspx</guid>
      <link>http://blog.andrewnurse.net/2008/12/11/BackingUpAZuneLibraryForWhenYouReinstallWindows.aspx</link>
      <pubDate>Thu, 11 Dec 2008 21:32:31 GMT</pubDate>
      <description>I regularly reinstall Windows, so when I used iTunes, I had to make sure I knew how to back up my music library (because I didn't want to re-rate all my songs :D).&amp;nbsp; I recently switched back to Zune from iTunes because I got so frustrated with my cracked iPod Touch screen.&amp;nbsp; Then, came the invevitable reinstall :)&lt;br&gt;
&lt;br&gt;
I keep my music on a separate partition, along with ALL my data (Folder Redirection
for the win!), so the music files aren't the problem.&amp;nbsp; With iTunes I could place
the music library database on the other drive too, but so far no luck there with the
Zune software (I'm going to check out Junctions to see if that will work).&amp;nbsp; So,
I resigned myself to digging through my AppData folder to see if I could find the
stuff I needed.&lt;br&gt;
&lt;br&gt;
For those who don't already know, the AppData folder, in Windows Vista is in: C:\Users\[UserName]\AppData.&amp;nbsp;
This is where programs (should) store their per-user settings and configuration data.&amp;nbsp;
Unfortunately (AFAIK) it's not possible to redirect this folder (like you can with
Documents, Music, etc.).&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
The Zune software stores its settings in C:\Users\[UserName]\AppData\Local\Microsoft\Zune.&amp;nbsp;
All I had to do was copy this folder over to my second partition, reinstall the OS
and reinstall the Zune software.&amp;nbsp; Then, I started the Zune software, just to
be sure and shut it down again.&amp;nbsp; I copied the backed up folder back into place,
restarted the Zune software and voila my library is back.&amp;nbsp; I was even able to
reconnect my Zune and have it automatically recognize it and sync!&lt;br&gt;
&lt;br&gt;
So, in summary:&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;
Back up C:\Users\[UserName]\AppData\Local\Microsoft\Zune&lt;/li&gt;
&lt;li&gt;
Reinstall Windows and other Apps&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
Reinstall Zune&lt;/li&gt;
&lt;li&gt;
Start Zune software (not sure if it's necessary, but it worked for me)&lt;/li&gt;
&lt;li&gt;
Shutdown Zune software&lt;/li&gt;
&lt;li&gt;
Copy backup back in to C:\Users\[UserName]\AppData\Local\Microsoft\Zune&lt;/li&gt;
&lt;li&gt;
Start Zune software and enjoy!&lt;/li&gt;
&lt;/ol&gt;
Let me know if that works for you, or if you have problems!&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=ec36b5af-6134-43b4-9cbd-8a74f3baeb54" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,ec36b5af-6134-43b4-9cbd-8a74f3baeb54.aspx</comments>
      <category>Tips</category>
      <category>Zune</category>
    </item>
  </channel>
</rss>