<?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/"
	>

<channel>
	<title>John Williams' Code Galaxy</title>
	<atom:link href="http://johnwilliams.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnwilliams.eu</link>
	<description>High-End VB.NET, ASP.NET and C# Source Code. Programming Tutorials.</description>
	<pubDate>Mon, 18 Jan 2010 11:23:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8220;A selected drive is no longer valid&#8221; quick workaround</title>
		<link>http://johnwilliams.eu/2009/11/a-selected-drive-is-no-longer-valid-quick-workaround/</link>
		<comments>http://johnwilliams.eu/2009/11/a-selected-drive-is-no-longer-valid-quick-workaround/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 16:38:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=322</guid>
		<description><![CDATA[Today I came across a problem with Visual Studio 2008 installation program. The following error occurred when I tried to add/remove Visual Studio components via control panel:
A selected drive is no longer valid
This error occurs after installation of Visual Studio 2008 SP1 (Service Pack 1), so you can no longer add or remove components of [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Today I came across a problem with Visual Studio 2008 installation program. The following error occurred when I tried to add/remove Visual Studio components via control panel:<br />
<em>A selected drive is no longer valid</em></p>
<p>This error occurs after installation of Visual Studio 2008 SP1 (Service Pack 1), so you can no longer add or remove components of the install.</p>
<p>In order to fix this error, you have two choices:</p>
<p>1. Uninstall SP1 via control panel, add necessary components to non-SP install, then apply SP1 again.</p>
<p>2. Locate and install required component manually. I was looking to add SQL Server Express Edition to my install. I found it at &#8220;\WCU\SSE\SQLEXPR.EXE&#8221; in Visual Studio 2008 installation folder (unpacked .ISO). This should work for other components accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/11/a-selected-drive-is-no-longer-valid-quick-workaround/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP AjaXplorer: limit upload by file extension</title>
		<link>http://johnwilliams.eu/2009/11/php-ajaxplorer-limit-upload-by-file-extension/</link>
		<comments>http://johnwilliams.eu/2009/11/php-ajaxplorer-limit-upload-by-file-extension/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 00:25:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=309</guid>
		<description><![CDATA[I had to add file management capability to one of my projects and encountered a serious issue. AjaXplorer FAQ says the following:
How can I filter some file extensions, both for display/download and for upload?
For the upload part, it’s not done via configuration, but you can easily hack one file to suit your needs. Open the [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I had to add file management capability to one of my projects and encountered a serious issue. AjaXplorer FAQ says the following:</p>
<p><em>How can I filter some file extensions, both for display/download and for upload?</p>
<p>For the upload part, it’s not done via configuration, but you can easily hack one file to suit your needs. Open the file client/html/flash_tpl.html at line 8 :<br />
You can see :<br />
&gt;&gt; $FlashVar = ‘&amp;fileTypes=*.*&amp;fileTypeDescription=All%20files&amp;totalUploadSize=’.$confTotalSize.’ [.... end of line]</p>
<p>You can edit the « fileTypes » and « fileTypeDescription » variable using for instance the following syntax :</p>
<p>&gt;&gt; [...]&amp;fileTypes=*.doc;*.jpg;*.gif&amp;fileTypeDescription=My%20Type%20Description&amp;[...]</em></p>
<p>However, the above method in not secure.</p>
<p>In AjaXplorer customization, if you need to *really* filter out files based on file extension, you have to customize the storage plugin. In my case &#8220;access.fs&#8221;, class.fsAccessDriver.php script. I wrote the following code to accomplish this task:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p309code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p3092"><td class="code" id="p309code2"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fancyLoader</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$userfile_name</span> <span style="color: #339933;">=</span> SystemTextEncoding<span style="color: #339933;">::</span><span style="color: #004000;">fromUTF8</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userfile_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Filtering code here</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/.*.(avi|flv|mpeg|mpg|wmv|divx)$/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$userfile_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$errorMessage</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;You can upload video files only&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This code will filter files on the server side and generate pop-up error if extension is not permitted. Furthermore, it works with non-flash uploader.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/11/php-ajaxplorer-limit-upload-by-file-extension/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Speed up your Visual Studio 2008!</title>
		<link>http://johnwilliams.eu/2009/11/speed-up-your-visual-studio-2008/</link>
		<comments>http://johnwilliams.eu/2009/11/speed-up-your-visual-studio-2008/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 09:52:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=304</guid>
		<description><![CDATA[5 simple steps to improve speed of your old VS 2008 bro

Install Visual Studio 2008 Service Pack 1. Download it here: http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&#38;displaylang=en
Remove unnecessary imported namespaces via &#8220;Project Properties&#8221;, &#8220;References tab&#8221;. Such imports significantly slow down the IDE.
Change your project compilation to x86 only, if you don&#8217;t need x64. This will improve compilation speed. &#8220;Project Properties&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p></p><h2>5 simple steps to improve speed of your old VS 2008 bro</h2>
<ol>
<li>Install Visual Studio 2008 Service Pack 1. Download it here: http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;displaylang=en</li>
<li>Remove unnecessary imported namespaces via &#8220;Project Properties&#8221;, &#8220;References tab&#8221;. Such imports significantly slow down the IDE.</li>
<li>Change your project compilation to x86 only, if you don&#8217;t need x64. This will improve compilation speed. &#8220;Project Properties&#8221;, &#8220;Compile&#8221; tab, &#8220;Advanced Compile Options&#8221;.</li>
<li>Install .NET Framework updates via Windows Update.</li>
<li>Defragment your hard disk.</li>
</ol>
<p>These four simple steps will make your Visual Studio 2008 fly!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/11/speed-up-your-visual-studio-2008/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Group Properties into Categories</title>
		<link>http://johnwilliams.eu/2009/11/group-properties-into-categories/</link>
		<comments>http://johnwilliams.eu/2009/11/group-properties-into-categories/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 09:33:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=291</guid>
		<description><![CDATA[
If you want to group your class / component / control properties into categories, such as Accessibility, Appearance, Behavior, Data, Design, etc., it&#8217;s very easy to accomplish. All you need is to put System.ComponentModel.Category attribute on top of a property:

View Code VBNET&#160;
    &#60;Category&#40;&#34;CoolCategory&#34;&#41;&#62; _
    Private categorizedPropertyValue As String
  [...]]]></description>
			<content:encoded><![CDATA[<p></p><p style="text-align: center;"><img class="aligncenter" title="Properties Categories" src="http://johnwilliams.eu/blog_files/Properties_Categories.png" alt="" width="243" height="243" /></p>
<p>If you want to group your class / component / control properties into categories, such as Accessibility, Appearance, Behavior, Data, Design, etc., it&#8217;s very easy to accomplish. All you need is to put System.ComponentModel.Category attribute on top of a property:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p291code5'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2915"><td class="code" id="p291code5"><pre class="vbnet" style="font-family:monospace;">&nbsp;
    &lt;Category<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;CoolCategory&quot;</span><span style="color: #000000;">&#41;</span>&gt; _
    <span style="color: #FF8000;">Private</span> categorizedPropertyValue <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
    <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Property</span> CategorizedProperty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
        <span style="color: #FF8000;">Get</span>
            <span style="color: #FF8000;">Return</span> categorizedPropertyValue
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span>
        <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
            categorizedPropertyValue <span style="color: #008000;">=</span> value
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span>
    <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p291code6'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2916"><td class="code" id="p291code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CoolCategory&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> categorizedPropertyValue<span style="color: #008000;">;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> CategorizedProperty <span style="color: #000000;">&#123;</span>
    get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> categorizedPropertyValue<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    set <span style="color: #000000;">&#123;</span> categorizedPropertyValue <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>When displayed in a PropertyGrid control, your property will appear in a new category (&#8221;CoolCategory&#8221; in this example). This feature is compatible with any .NET language, including VB.NET and C#.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/11/group-properties-into-categories/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Use WIA to retrieve images from scanner, digital camera or webcam using VB.NET and C#.</title>
		<link>http://johnwilliams.eu/2009/09/use-wia-to-retrieve-images-from-scanner-digital-camera-or-webcam-using-vbnet-and-csharp/</link>
		<comments>http://johnwilliams.eu/2009/09/use-wia-to-retrieve-images-from-scanner-digital-camera-or-webcam-using-vbnet-and-csharp/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 10:05:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[CSharp]]></category>

		<category><![CDATA[digital camera]]></category>

		<category><![CDATA[Imaging]]></category>

		<category><![CDATA[imaging devices]]></category>

		<category><![CDATA[scanner]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[webcam]]></category>

		<category><![CDATA[WIA]]></category>

		<category><![CDATA[WIALib]]></category>

		<category><![CDATA[Windows Image Acquisition]]></category>

		<category><![CDATA[wrapper]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=253</guid>
		<description><![CDATA[Get images from scanner, webcam or any other type of imaging device
Here&#8217;s the class that I wrote to extract images from various imaging devices via VB.NET and C#.
WIA (Windows Image Acquisition) supports the following types of devices:

Scanners
Digital Cameras
Webcams

The class correctly communicates with Windows Image Acquisition Library (WIALib), releases all COM objects used and allows you [...]]]></description>
			<content:encoded><![CDATA[<p></p><h2>Get images from scanner, webcam or any other type of imaging device</h2>
<p>Here&#8217;s the class that I wrote to extract images from various imaging devices via VB.NET and C#.</p>
<p>WIA (Windows Image Acquisition) supports the following types of devices:</p>
<ul>
<li>Scanners</li>
<li>Digital Cameras</li>
<li>Webcams</li>
</ul>
<p>The class correctly communicates with Windows Image Acquisition Library (WIALib), releases all COM objects used and allows you to select between single image or multiple images acquisition.</p>
<p>Downloadable package contains actual library that can be used with any of your projects and two demo projects (VB.NET and C#).</p>
<p>If you don&#8217;t want to download source code, you can copy it from the code box below.</p>
<h2>WIA Wrapper Library, VB.NET Version</h2>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p253code9'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2539"><td class="code" id="p253code9"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Drawing</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Runtime</span>.<span style="color: #0000FF;">InteropServices</span>
<span style="color: #0600FF;">Imports</span> WIALib
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> ImageRetriever
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Function</span> RetriveImages<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> selectionMode <span style="color: #FF8000;">As</span> ImageSelectionMode<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> List<span style="color: #000000;">&#40;</span>Of Bitmap<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> comObjects <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> List<span style="color: #000000;">&#40;</span>Of <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Create WIA COM objects</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Manager</span>
        <span style="color: #0600FF;">Dim</span> manager <span style="color: #FF8000;">As</span> WiaClass <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>manager<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Devices collection</span>
        <span style="color: #0600FF;">Dim</span> devices <span style="color: #FF8000;">As</span> CollectionClass <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>devices<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Root device</span>
        <span style="color: #0600FF;">Dim</span> rootDevice <span style="color: #FF8000;">As</span> ItemClass <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>rootDevice<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Collection</span>
        <span style="color: #0600FF;">Dim</span> pictures <span style="color: #FF8000;">As</span> CollectionClass <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pictures<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Image</span>
        <span style="color: #0600FF;">Dim</span> pictureItem <span style="color: #FF8000;">As</span> ItemClass <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pictureItem<span style="color: #000000;">&#41;</span>
&nbsp;
        manager <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> WiaClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        devices <span style="color: #008000;">=</span> TryCast<span style="color: #000000;">&#40;</span>manager.<span style="color: #0000FF;">Devices</span>, CollectionClass<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Retrieve all devices</span>
        <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>devices <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span><span style="color: #000000;">&#41;</span> OrElse <span style="color: #000000;">&#40;</span>devices.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            DisposeComObjects<span style="color: #000000;">&#40;</span>comObjects<span style="color: #000000;">&#41;</span>
            <span style="color: #FF8000;">Throw</span> <span style="color: #FF8000;">New</span> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No devices found.&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> UISelection <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span> <span style="color: #008000;">=</span> System.<span style="color: #0000FF;">Reflection</span>.<span style="color: #0000FF;">Missing</span>.<span style="color: #0000FF;">Value</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'WIA dialog, allows user to select a device</span>
        rootDevice <span style="color: #008000;">=</span> DirectCast<span style="color: #000000;">&#40;</span>manager.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>UISelection<span style="color: #000000;">&#41;</span>, ItemClass<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">If</span> rootDevice <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #FF8000;">Throw</span> <span style="color: #FF8000;">New</span> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No device selected.&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'WIA dialog, allows user to select a picture.</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> flag <span style="color: #FF8000;">As</span> WiaFlag <span style="color: #008000;">=</span> WiaFlag.<span style="color: #0000FF;">SingleImage</span>
        <span style="color: #0600FF;">If</span> selectionMode <span style="color: #008000;">=</span> ImageSelectionMode.<span style="color: #0000FF;">Multiple</span> <span style="color: #FF8000;">Then</span> flag <span style="color: #008000;">=</span> WiaFlag.<span style="color: #0000FF;">UseCommonUI</span>
&nbsp;
        pictures <span style="color: #008000;">=</span> TryCast<span style="color: #000000;">&#40;</span>rootDevice.<span style="color: #0000FF;">GetItemsFromUI</span><span style="color: #000000;">&#40;</span>flag, WiaIntent.<span style="color: #0000FF;">ImageTypeColor</span><span style="color: #000000;">&#41;</span>, CollectionClass<span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">If</span> pictures <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span>
            DisposeComObjects<span style="color: #000000;">&#40;</span>comObjects<span style="color: #000000;">&#41;</span>
            <span style="color: #FF8000;">Throw</span> <span style="color: #FF8000;">New</span> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No pictures selected.&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> bitmapList <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> List<span style="color: #000000;">&#40;</span>Of Bitmap<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> picture <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span> In pictures
&nbsp;
            <span style="color: #0600FF;">Dim</span> filePath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> Path.<span style="color: #0000FF;">GetTempFileName</span>
            pictureItem <span style="color: #008000;">=</span> DirectCast<span style="color: #000000;">&#40;</span>Marshal.<span style="color: #0000FF;">CreateWrapperOfType</span><span style="color: #000000;">&#40;</span>picture, <span style="color: #804040;">GetType</span><span style="color: #000000;">&#40;</span>ItemClass<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, ItemClass<span style="color: #000000;">&#41;</span>
            pictureItem.<span style="color: #0000FF;">Transfer</span><span style="color: #000000;">&#40;</span>filePath, <span style="color: #0600FF;">False</span><span style="color: #000000;">&#41;</span>
&nbsp;
            bitmapList.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Image.<span style="color: #0000FF;">FromFile</span><span style="color: #000000;">&#40;</span>filePath<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Release COM object</span>
            Marshal.<span style="color: #0000FF;">ReleaseComObject</span><span style="color: #000000;">&#40;</span>picture<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #FF8000;">Next</span>
&nbsp;
        <span style="color: #FF8000;">Return</span> bitmapList
&nbsp;
        DisposeComObjects<span style="color: #000000;">&#40;</span>comObjects<span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> DisposeComObjects<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> objects <span style="color: #FF8000;">As</span> List<span style="color: #000000;">&#40;</span>Of <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> comObject In objects
            <span style="color: #0600FF;">If</span> comObject <span style="color: #FF8000;">IsNot</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span>
                Marshal.<span style="color: #0000FF;">ReleaseComObject</span><span style="color: #000000;">&#40;</span>comObject<span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        <span style="color: #FF8000;">Next</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> AcquisitionException
    <span style="color: #0600FF;">Inherits</span> Exception
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> <span style="color: #FF8000;">New</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> message <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">MyBase</span>.<span style="color: #FF8000;">New</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Enum</span> ImageSelectionMode
    One <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
    Multiple <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Enum</span></pre></td></tr></table></div>

<h2>WIA Wrapper Class, CSharp version</h2>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p253code10'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p25310"><td class="code" id="p253code10"><pre class="csharp" style="font-family:monospace;">&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">WIALib</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ImageRetriever
<span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>Bitmap<span style="color: #008000;">&gt;</span> RetriveImages<span style="color: #000000;">&#40;</span>ImageSelectionMode selectionMode<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
        List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> comObjects <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Create WIA COM objects</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Manager</span>
        WiaClass manager <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>manager<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Devices collection</span>
        CollectionClass devices <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>devices<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Root device</span>
        ItemClass rootDevice <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>rootDevice<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Collection</span>
        CollectionClass pictures <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pictures<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Image</span>
        ItemClass pictureItem <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        comObjects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pictureItem<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        manager <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WiaClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        devices <span style="color: #008000;">=</span> manager.<span style="color: #0000FF;">Devices</span> <span style="color: #0600FF;">as</span> CollectionClass<span style="color: #008000;">;</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">//Retrieve all devices</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>devices <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #000000;">&#40;</span>devices.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            DisposeComObjects<span style="color: #000000;">&#40;</span>comObjects<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;No devices found.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #FF0000;">object</span> UISelection <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span>.<span style="color: #0000FF;">Missing</span>.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">//WIA dialog, allows user to select a device</span>
        rootDevice <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ItemClass<span style="color: #000000;">&#41;</span>manager.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>UISelection<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>rootDevice <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;No device selected.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//WIA dialog, allows user to select a picture.</span>
&nbsp;
        WiaFlag flag <span style="color: #008000;">=</span> WiaFlag.<span style="color: #0000FF;">SingleImage</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>selectionMode <span style="color: #008000;">==</span> ImageSelectionMode.<span style="color: #0000FF;">Multiple</span><span style="color: #000000;">&#41;</span> flag <span style="color: #008000;">=</span> WiaFlag.<span style="color: #0000FF;">UseCommonUI</span><span style="color: #008000;">;</span> 
&nbsp;
&nbsp;
        pictures <span style="color: #008000;">=</span> rootDevice.<span style="color: #0000FF;">GetItemsFromUI</span><span style="color: #000000;">&#40;</span>flag, WiaIntent.<span style="color: #0000FF;">ImageTypeColor</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CollectionClass<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>pictures <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            DisposeComObjects<span style="color: #000000;">&#40;</span>comObjects<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;No pictures selected.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        List<span style="color: #008000;">&lt;</span>Bitmap<span style="color: #008000;">&gt;</span> bitmapList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>Bitmap<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> picture <span style="color: #0600FF;">in</span> pictures<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #FF0000;">string</span> filePath <span style="color: #008000;">=</span> Path.<span style="color: #0000FF;">GetTempFileName</span><span style="color: #008000;">;</span>
            pictureItem <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ItemClass<span style="color: #000000;">&#41;</span>Marshal.<span style="color: #0000FF;">CreateWrapperOfType</span><span style="color: #000000;">&#40;</span>picture, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>ItemClass<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            pictureItem.<span style="color: #0000FF;">Transfer</span><span style="color: #000000;">&#40;</span>filePath, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            bitmapList.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Image.<span style="color: #0000FF;">FromFile</span><span style="color: #000000;">&#40;</span>filePath<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Release COM object</span>
&nbsp;
            Marshal.<span style="color: #0000FF;">ReleaseComObject</span><span style="color: #000000;">&#40;</span>picture<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF;">return</span> bitmapList<span style="color: #008000;">;</span>
&nbsp;
&nbsp;
&nbsp;
        DisposeComObjects<span style="color: #000000;">&#40;</span>comObjects<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> DisposeComObjects<span style="color: #000000;">&#40;</span>List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> objects<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var comObject <span style="color: #0600FF;">in</span> objects<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>comObject <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                Marshal.<span style="color: #0000FF;">ReleaseComObject</span><span style="color: #000000;">&#40;</span>comObject<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> AcquisitionException <span style="color: #008000;">:</span> Exception
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> AcquisitionException<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> message<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> ImageSelectionMode
<span style="color: #000000;">&#123;</span>
    One <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
    Multiple <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h2>Downloadable version</h2>
<p><a href="http://johnwilliams.eu/howtoseries/files/WIA Scripting.zip">Download full package</a></p>
<p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/09/use-wia-to-retrieve-images-from-scanner-digital-camera-or-webcam-using-vbnet-and-csharp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Strict VB.NET</title>
		<link>http://johnwilliams.eu/2009/09/strict-vb-net/</link>
		<comments>http://johnwilliams.eu/2009/09/strict-vb-net/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 08:21:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[compiler configuration]]></category>

		<category><![CDATA[Microsoft.VisualBasic]]></category>

		<category><![CDATA[references]]></category>

		<category><![CDATA[strict vb.net]]></category>

		<category><![CDATA[vb6]]></category>

		<category><![CDATA[visual basic namespace]]></category>

		<category><![CDATA[warning configuration]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=241</guid>
		<description><![CDATA[Sometimes VB.NET is considered less powerful than C#. This isn&#8217;t true, all .NET languages have equal abilities.
The only difference is that VB.NET allows too many liberties in default configuration.
Old VB Compatibility Namespace
The first unnecessary thing consists of imported Visual Basic 6 Compatibility Namespace (Microsoft.VisualBasic). If you wish to become a true .NET programmer, you have [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Sometimes VB.NET is considered less powerful than C#. This isn&#8217;t true, all .NET languages have equal abilities.<br />
The only difference is that VB.NET allows too many liberties in default configuration.</p>
<h2>Old VB Compatibility Namespace</h2>
<p>The first unnecessary thing consists of imported Visual Basic 6 Compatibility Namespace (Microsoft.VisualBasic). If you wish to become a true .NET programmer, you have to remove it. For almost every VB6 function there&#8217;s a replacement in .NET Framework. If you won&#8217;t use old compatibility functions, it will become possible to convert your code to other .NET languages without any problem.<br />
So go ahead and remove it via <em>Project</em>, &#8220;<em>ProjectName Properties</em>&#8220;, &#8220;<em>References</em>&#8221; tab.</p>
<div class="wp-caption aligncenter" style="width: 332px">
	<img title="Remove VB Compatibility Namespace" src="http://johnwilliams.eu/wp-content/uploads/2009/09/Remove_VB_Compatibility_Namespace.PNG" alt="Remove VB Compatibility Namespace" width="332" height="340" />
	<p class="wp-caption-text">Remove VB Compatibility Namespace</p>
</div>
<h2>Compile Options. Warning Configurations.</h2>
<p>In VB.NET, there&#8217;s no even a warning in regard to implicit type conversion, late binding or object assumption by default. This may lead to potential errors or low performance of the code.</p>
<p>If you want fast and reliable code, you have to change &#8220;<em>None</em>&#8221; at least to &#8220;<em>Warning</em>&#8221; or even &#8220;<em>Error</em>&#8220;.</p>
<p>The first three entries of configuration are the most important. They can be changed via &#8220;<em>Project</em>&#8220;, &#8220;<em>ProjectName Properties</em>&#8220;, &#8220;<em>Compile</em>&#8221; tab.</p>
<p style="text-align: center;"><img class="  aligncenter" title="Change Default Warning Configurations in Compile Options Tab" src="http://johnwilliams.eu/wp-content/uploads/2009/09/Change_Warning_Configurations_in_Compiler Options.PNG" alt="Change Default Warning Configurations in Compile Options Tab" width="579" height="275" /></p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/09/strict-vb-net/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Open a specific key in regedit</title>
		<link>http://johnwilliams.eu/2009/09/open-a-specific-key-in-regedit/</link>
		<comments>http://johnwilliams.eu/2009/09/open-a-specific-key-in-regedit/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 09:52:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Applets]]></category>

		<category><![CDATA[lastkey]]></category>

		<category><![CDATA[open hive]]></category>

		<category><![CDATA[open key]]></category>

		<category><![CDATA[open specific key]]></category>

		<category><![CDATA[regedit]]></category>

		<category><![CDATA[Registry Editor]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=231</guid>
		<description><![CDATA[Regedit Open Key
Unfortunately, there&#8217;s no command-line switch to open a specific key in Windows Registry Editor. However, the task can be achieved via LastKeyvalue of Applets key. If you need to open a hive in regedit, you can use C# and VB.NET code located below.
Regedit Open Hive

View Code CSHARPusing Microsoft.Win32.Registry;
using Microsoft.Win32;
using System.IO;
&#160;
public class RegEditKeyOpener
&#123;
&#160;
	public void [...]]]></description>
			<content:encoded><![CDATA[<p></p><h2>Regedit Open Key</h2>
<p>Unfortunately, there&#8217;s no command-line switch to open a specific key in Windows Registry Editor. However, the task can be achieved via <em>LastKey</em>value of <em>Applets</em> key. If you need to open a hive in regedit, you can use C# and VB.NET code located below.</p>
<h2>Regedit Open Hive</h2>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code13'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p23113"><td class="code" id="p231code13"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Win32.Registry</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Win32</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> RegEditKeyOpener
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Open<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> keyPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>RegistryKey regeditKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Software<span style="color: #008080; font-weight: bold;">\\</span>Microsoft<span style="color: #008080; font-weight: bold;">\\</span>Windows<span style="color: #008080; font-weight: bold;">\\</span>CurrentVersion<span style="color: #008080; font-weight: bold;">\\</span>Applets<span style="color: #008080; font-weight: bold;">\\</span>RegEdit&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">//Example: My Computer\HKEY_CURRENT_USER\Software\WinRAR SFX</span>
			regeditKey.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;LastKey&quot;</span>, keyPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			Process.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;regedit&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code14'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p23114"><td class="code" id="p231code14"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> Microsoft.<span style="color: #0600FF;">Win32</span>.<span style="color: #0000FF;">Registry</span>
<span style="color: #0600FF;">Imports</span> Microsoft.<span style="color: #0600FF;">Win32</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> RegEditKeyOpener
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> <span style="color: #0600FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> keyPath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
Using regeditKey <span style="color: #FF8000;">As</span> RegistryKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software\Microsoft\Windows\CurrentVersion\Applets\RegEdit&quot;</span>, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-style: italic;">'Example: My Computer\HKEY_CURRENT_USER\Software\WinRAR SFX</span>
regeditKey.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;LastKey&quot;</span>, keyPath<span style="color: #000000;">&#41;</span>
Process.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;regedit&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> Using
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/09/open-a-specific-key-in-regedit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to override .NET two connections per-server limit</title>
		<link>http://johnwilliams.eu/2009/09/how-to-override-net-two-connections-per-server-limit/</link>
		<comments>http://johnwilliams.eu/2009/09/how-to-override-net-two-connections-per-server-limit/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 22:09:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ConnectionManagementElement]]></category>

		<category><![CDATA[ConnectionManagementElement DefaultConnectionLimit]]></category>

		<category><![CDATA[connections limit]]></category>

		<category><![CDATA[MaxConnection]]></category>

		<category><![CDATA[override]]></category>

		<category><![CDATA[ServicePointManager]]></category>

		<category><![CDATA[System.Configuration]]></category>

		<category><![CDATA[two connections]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=218</guid>
		<description><![CDATA[There&#8217;s a secret - entire .NET application connectivity is limited to 2 connections per server by default. This is a good thing to protect servers from overloading and to encourage developer consciousness, but every benefit can have a dark side as well. If you need to override this limit for some reason, you can use [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>There&#8217;s a secret - entire .NET application connectivity is limited to 2 connections per server by default. This is a good thing to protect servers from overloading and to encourage developer consciousness, but every benefit can have a dark side as well. If you need to override this limit for some reason, you can use the following code. Don&#8217;t forget to add a reference to <em>System.Configuration</em> assembly in your project.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p218code17'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p21817"><td class="code" id="p218code17"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#123;</span>
<span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">Configuration</span>.<span style="color: #0000FF;">ConnectionManagementElement</span> managerElement <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">Configuration</span>.<span style="color: #0000FF;">ConnectionManagementElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
managerElement.<span style="color: #0000FF;">MaxConnection</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span><span style="color: #008000;">;</span>
<span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">ServicePointManager</span>.<span style="color: #0000FF;">DefaultConnectionLimit</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p218code18'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p21818"><td class="code" id="p218code18"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> managerElement <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> System.<span style="color: #0000FF;">Net</span>.<span style="color: #0000FF;">Configuration</span>.<span style="color: #0000FF;">ConnectionManagementElement</span>
managerElement.<span style="color: #0000FF;">MaxConnection</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span>
System.<span style="color: #0000FF;">Net</span>.<span style="color: #0000FF;">ServicePointManager</span>.<span style="color: #0000FF;">DefaultConnectionLimit</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/09/how-to-override-net-two-connections-per-server-limit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>.NET Registry Tutorial</title>
		<link>http://johnwilliams.eu/2009/09/dotnet-registry-tutorial/</link>
		<comments>http://johnwilliams.eu/2009/09/dotnet-registry-tutorial/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 14:05:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[CurrentUser]]></category>

		<category><![CDATA[Enumeration]]></category>

		<category><![CDATA[framework]]></category>

		<category><![CDATA[GetSubKeyNames]]></category>

		<category><![CDATA[GetValue]]></category>

		<category><![CDATA[LocalMachine]]></category>

		<category><![CDATA[Microsoft.Win32]]></category>

		<category><![CDATA[Microsoft.Win32.Registry]]></category>

		<category><![CDATA[Registry]]></category>

		<category><![CDATA[RegistryKey]]></category>

		<category><![CDATA[SetValue]]></category>

		<category><![CDATA[SubKeys]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[Values]]></category>

		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=189</guid>
		<description><![CDATA[Let&#8217;s learn how to work with .NET Registry Classes in several simple steps.
Preparation
Let&#8217;s prepare nice environment for our registry work. Open your copy of Visual Studio 2008 and create new console application.
Registry namespace import
Open your application&#8217;s code. Add &#8220;using Microsoft.Win32;&#8221; and &#8220;using Microsoft.Win32.Registry;&#8221; to the top. If you&#8217;re in VB, add  Imports Microsoft.Win32.Registry and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Let&#8217;s learn how to work with .NET Registry Classes in several simple steps.</p>
<h2>Preparation</h2>
<p>Let&#8217;s prepare nice environment for our registry work. Open your copy of Visual Studio 2008 and create new console application.</p>
<h2>Registry namespace import</h2>
<p>Open your application&#8217;s code. Add &#8220;<em>using Microsoft.Win32;</em>&#8221; and &#8220;<em>using Microsoft.Win32.Registry;</em>&#8221; to the top. If you&#8217;re in VB, add  <em>Imports Microsoft.Win32.Registry</em> and <em>Imports Microsoft.Win32</em> . It doesn&#8217;t matter what class will you use and default start-up class can be used.</p>
<h2>A bit of theory</h2>
<p>In .NET, registry manipulations can be achieved via <em>Registry</em> class and corresponding <em>RegistryKey</em> class.</p>
<p>The keys are separated into 7 main categories. <em>CurrentUser</em> and <em>LocalMachine</em> are the most often used ones. A key can be open as writable or read-only. Each RegistryKey may contain <em>SubKeys</em> and <em>Values.</em></p>
<p>Here&#8217;s a full list of root keys: ClassesRoot, CurrentConfig, CurrentUser, DynData, LocalMachine, PerformanceData, Users.</p>
<p>Using these classes, you can create, enumerate and delete  new keys. Additionally, you can enumerate, retrieve and assign key values.</p>
<h2>First trick - enumerate the keys</h2>
<p>Enough theory. Let&#8217;s get down to business. In this part, we&#8217;ll enumerate key names of software that belongs to current user.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code25'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18925"><td class="code" id="p189code25"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>RegistryKey softwareKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Software&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var subKeyName <span style="color: #0600FF;">in</span> softwareKey.<span style="color: #0000FF;">GetSubKeyNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Key: {0}&quot;</span>, subKeyName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code26'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18926"><td class="code" id="p189code26"><pre class="vbnet" style="font-family:monospace;">Using softwareKey <span style="color: #FF8000;">As</span> RegistryKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> subKeyName In softwareKey.<span style="color: #0000FF;">GetSubKeyNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">String</span>.<span style="color: #0600FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Key: {0}&quot;</span>, subKeyName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Next</span>
&nbsp;
<span style="color: #0600FF;">End</span> Using</pre></td></tr></table></div>

<p>Upon execution of the above code, console window should be populated with various entries.</p>
<h2>Our own registry key</h2>
<p>We can create a registry key for our own software. It can be used to store various settings.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code27'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18927"><td class="code" id="p189code27"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//Open the software key of the current user. Must be opened as writable.</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>RegistryKey softwareKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Software&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Attempt to open our key if it's already created. Open as writable.</span>
        RegistryKey ourRegistryKey <span style="color: #008000;">=</span> softwareKey.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MyCalculator&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">//If it's not there, attempt to create it</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ourRegistryKey <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> ourRegistryKey <span style="color: #008000;">=</span> softwareKey.<span style="color: #0000FF;">CreateSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MyCalculator&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
&nbsp;
        <span style="color: #008080; font-style: italic;">//Read current data of &quot;MyPath&quot; value</span>
        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;My path: {0}&quot;</span>, ourRegistryKey.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MyPath&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">//And assign the new one</span>
&nbsp;
        ourRegistryKey.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MyPath&quot;</span>, Application.<span style="color: #0000FF;">StartupPath</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code28'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18928"><td class="code" id="p189code28"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'Open the software key of the current user. Must be opened as writable.</span>
Using softwareKey <span style="color: #FF8000;">As</span> RegistryKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software&quot;</span>, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Attempt to open our key if it's already created. Open as writable.</span>
<span style="color: #0600FF;">Dim</span> ourRegistryKey <span style="color: #FF8000;">As</span> RegistryKey <span style="color: #008000;">=</span> softwareKey.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MyCalculator&quot;</span>, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-style: italic;">'If it's not there, attempt to create it</span>
<span style="color: #0600FF;">If</span> ourRegistryKey <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span> ourRegistryKey <span style="color: #008000;">=</span> softwareKey.<span style="color: #0000FF;">CreateSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MyCalculator&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Read current data of &quot;MyPath&quot; value</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">String</span>.<span style="color: #0600FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;My path: {0}&quot;</span>, ourRegistryKey.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MyPath&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-style: italic;">'And assign the new one</span>
ourRegistryKey.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MyPath&quot;</span>, Application.<span style="color: #0000FF;">StartupPath</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">End</span> Using</pre></td></tr></table></div>

<h2>&#8220;Advanced&#8221; technique. Register our software for start up with Windows.</h2>
<p>Here&#8217;s how we can add our software to the automatic start-up list of the current user. Startup path must be quote-wrapped.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code29'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18929"><td class="code" id="p189code29"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#123;</span>
    RegistryKey autoStartKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Software<span style="color: #008080; font-weight: bold;">\\</span>Microsoft<span style="color: #008080; font-weight: bold;">\\</span>Windows<span style="color: #008080; font-weight: bold;">\\</span>CurrentVersion<span style="color: #008080; font-weight: bold;">\\</span>Run&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    autoStartKey.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MySoftwareName&quot;</span>, <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}{1}{0}&quot;</span>, <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, Application.<span style="color: #0000FF;">ExecutablePath</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code30'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18930"><td class="code" id="p189code30"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> autoStartKey <span style="color: #FF8000;">As</span> RegistryKey <span style="color: #008000;">=</span> Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span> _
<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software\\Microsoft\\Windows\\CurrentVersion\\Run&quot;</span>, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
autoStartKey.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MySoftwareName&quot;</span>, <span style="color: #FF8000;">String</span>.<span style="color: #0600FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;{0}{1}{0}&quot;</span>, <span style="color: #808080;">&quot;&quot;</span><span style="color: #808080;">&quot;&quot;</span>, Application.<span style="color: #0000FF;">ExecutablePath</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>If you want to register start-up for all users, simply replace <em>Registry.CurrentUser.OpenSubKey </em>in the above code with <em>Registry.LocalMachine.OpenSubKey</em>. Note that administrative permission will be needed for system-wide changes.</p>
<p>Now you&#8217;re familiar with some basic and even advanced registry manipulation techniques.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/09/dotnet-registry-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>5 Common .NET Mistakes</title>
		<link>http://johnwilliams.eu/2009/09/5-common-net-mistakes/</link>
		<comments>http://johnwilliams.eu/2009/09/5-common-net-mistakes/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 12:05:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[.NET]]></category>

		<category><![CDATA[class library]]></category>

		<category><![CDATA[classes]]></category>

		<category><![CDATA[commenting]]></category>

		<category><![CDATA[content]]></category>

		<category><![CDATA[development cycle]]></category>

		<category><![CDATA[errors]]></category>

		<category><![CDATA[exceptions]]></category>

		<category><![CDATA[exceptions handling]]></category>

		<category><![CDATA[FileNotFoundException]]></category>

		<category><![CDATA[framework]]></category>

		<category><![CDATA[functions]]></category>

		<category><![CDATA[GAC]]></category>

		<category><![CDATA[Global Assembly Cache]]></category>

		<category><![CDATA[library]]></category>

		<category><![CDATA[mistakes]]></category>

		<category><![CDATA[multi threading]]></category>

		<category><![CDATA[namespaces]]></category>

		<category><![CDATA[Nothing]]></category>

		<category><![CDATA[Null]]></category>

		<category><![CDATA[NullReferenceException]]></category>

		<category><![CDATA[object]]></category>

		<category><![CDATA[object-oriented model]]></category>

		<category><![CDATA[references]]></category>

		<category><![CDATA[regions]]></category>

		<category><![CDATA[resources]]></category>

		<category><![CDATA[runtime errors]]></category>

		<category><![CDATA[subs]]></category>

		<category><![CDATA[System.IO]]></category>

		<category><![CDATA[System.Windows.Forms.Clipboard]]></category>

		<category><![CDATA[thread safety]]></category>

		<category><![CDATA[try catch block]]></category>

		<category><![CDATA[webbrowser control]]></category>

		<guid isPermaLink="false">http://johnwilliams.eu/?p=187</guid>
		<description><![CDATA[This time I&#8217;m going to name 5 most common reasons of errors in .NET programming.
This is something that experienced programmer should avoid.  Let&#8217;s proceed.
Incorrect multithreading
Most of developers want to enhance their applications with multithreading capabilities. For some projects such enhancements are beneficial, however, they might be a burden for others. Furthermore, poorly written multi-threading code [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>This time I&#8217;m going to name 5 most common reasons of errors in .NET programming.</p>
<p>This is something that experienced programmer should avoid.  Let&#8217;s proceed.</p>
<h2>Incorrect multithreading</h2>
<p>Most of developers want to enhance their applications with multithreading capabilities. For some projects such enhancements are beneficial, however, they might be a burden for others. Furthermore, <span>poorly written multi-threading code can lead to unexpected results and runtime errors.</span></p>
<p><span>Some controls and classes are not thread-safe. This means that you have to invoke them via the same thread, that originally created them. Good examples of thread-unsafe items would be WebBrowser control and System.Windows.Forms.Clipboard class. Even if they work at some time, such classes may crash in the process, if you haven&#8217;t considered thread safety carefully.<br />
</span></p>
<h2>Null Reference error</h2>
<p>System.NullReferenceException is considered to be hard to debug. At the same time, it&#8217;s a common <span>filth that makes life more difficult for amateurs</span><span>.</span></p>
<p>This exception occurs due to fact that object reference hasn&#8217;t been assigned to an instance of an object. Every time there&#8217;s a chance that object can be Null (Nothing in Visual Basic), you should check whether the reference is set:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p187code33'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18733"><td class="code" id="p187code33"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#123;</span>
<span style="color: #FF0000;">object</span> myObject <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>myObject <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-style: italic;">//Do some stuff with the object</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #008080; font-style: italic;">//Don't use the object in order to avoid NullReferenceException</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p187code34'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18734"><td class="code" id="p187code34"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> myObject <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> <span style="color: #FF0000;">Object</span>
<span style="color: #0600FF;">If</span> myObject <span style="color: #FF8000;">IsNot</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Do some stuff with the object</span>
&nbsp;
<span style="color: #FF8000;">Else</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Don't use the object in order to avoid NullReferenceException</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></td></tr></table></div>

<p>Alternatively,  <em>if (myObject == null) </em><em>(If </em><em>myObject </em><em>Is Nothing </em>in VB) can be used.</p>
<h2>Missing DDL&#8217;s and other types of files</h2>
<p>Every time you reference a class library you have to make sure that the assembly will exist either in GAC (Global Assembly Cache) or the same directory where original assembly resides.</p>
<p>It is a good practice to set &#8220;Copy Local&#8221; property of each assembly you&#8217;ve referenced to True. This property can be accessed via project properties, &#8220;References&#8221; tab.</p>
<p>Never forget to include important application files into resources or <em>content </em>section. Such files should be also included into installation packages.</p>
<h2>Inappropriate exceptions handling</h2>
<p>You should NEVER use &#8220;Try-Catch&#8221; block to CONCEAL an exception. Such actions would lead to almost untraceable errors. If an exception occurs in some part of the code, you should find a proper way to handle it. Keep in mind that exception handling also consumes large amount of processor&#8217;s time. If known exception occurs somewhere in your code, you should fix it, not hide. For example, use  System.IO.File.Exists function to check whether the file exists and don&#8217;t use FileNotFoundException handling for that. In real life, it is inappropriate to treat fire alarm as something normal. A similar approach should be used for .NET applications if you want to make them stable.</p>
<h2>Unclear code and missing comments</h2>
<p>Debugging is one of the most important parts of application development cycle. If you write unclear code, debugging can become difficult.</p>
<p>Separate your code into classes, subs and functions. Good object-oriented model is a guarantee of painless development cycle. Use <em>regions</em> and <em>namespaces </em>where appropriate. Commenting will make life easier for you and for other developers, who might need to work with your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnwilliams.eu/2009/09/5-common-net-mistakes/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
