<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Roberto Mencia&#039;s blog</title>
	<atom:link href="http://rmencia.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rmencia.wordpress.com</link>
	<description>Born to surf, forced to develop!</description>
	<lastBuildDate>Thu, 26 Jan 2012 01:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rmencia.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Roberto Mencia&#039;s blog</title>
		<link>http://rmencia.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rmencia.wordpress.com/osd.xml" title="Roberto Mencia&#039;s blog" />
	<atom:link rel='hub' href='http://rmencia.wordpress.com/?pushpress=hub'/>
		<item>
		<title>We won the WORLD CUP!!!!</title>
		<link>http://rmencia.wordpress.com/2010/07/11/we-won-the-world-cup/</link>
		<comments>http://rmencia.wordpress.com/2010/07/11/we-won-the-world-cup/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 23:28:35 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://rmencia.wordpress.com/2010/07/11/we-won-the-world-cup/</guid>
		<description><![CDATA[Somos campeones del mundo!! We are the champions!!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=132&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Somos campeones del mundo!!</p>
<p>We are the champions!!</p>
<p><a href="http://rmencia.files.wordpress.com/2010/07/img_0302medium.jpg"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="IMG_0302 (Medium)" border="0" alt="IMG_0302 (Medium)" src="http://rmencia.files.wordpress.com/2010/07/img_0302medium_thumb.jpg?w=454&#038;h=604" width="454" height="604" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=132&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2010/07/11/we-won-the-world-cup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2010/07/img_0302medium_thumb.jpg" medium="image">
			<media:title type="html">IMG_0302 (Medium)</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating Windows OEM recovery DVDs with Windows AIK (part 2)</title>
		<link>http://rmencia.wordpress.com/2010/07/09/creating-windows-oem-recovery-dvds-with-windows-aik-part-2/</link>
		<comments>http://rmencia.wordpress.com/2010/07/09/creating-windows-oem-recovery-dvds-with-windows-aik-part-2/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 05:26:09 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[Windows AIK]]></category>
		<category><![CDATA[WAIK]]></category>

		<guid isPermaLink="false">https://rmencia.wordpress.com/2010/07/09/creating-windows-oem-recovery-dvds-with-windows-aik-part-2/</guid>
		<description><![CDATA[In this post I’m going to continue creating the scripts (and manual steps) to restore the windows image file and show alternatives to the creation of the DVDs. To fully understand the process I recommend reading the part 1 of this series. &#160; By now you should have your set of restoring DVDs and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=118&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I’m going to continue creating the scripts (and manual steps) to restore the windows image file and show alternatives to the creation of the DVDs. To fully understand the process I recommend reading the <a href="http://rmencia.wordpress.com/2010/07/07/creating-windows-oem-recovery-dvds-with-windows-aik-part-1">part 1</a> of this series.</p>
<p>&#160;</p>
<p>By now you should have your set of restoring DVDs and the bootable DVD that includes the tools required to continue the process.</p>
<p>I’m going to start explaining the manual steps to restore the image, so you can understand what’s going on, and then I’ll give you the code for the <em>restore.cmd</em> script that can be used to restore the system automatically.</p>
<p>&#160;</p>
<h1><font color="#000080">Important!!</font></h1>
<p>Go and get yourself a coffee while you back-up your data, as the restoring process described here cleans the hard drive.</p>
<p>&#160;</p>
<h1><font color="#000080">Create partitions</font></h1>
<p>The first thing the we need to do is to clean the disk and create the partitions. To do that we will use diskpart. </p>
<p>The process involves creating 2 partitions. The first one is for Windows. Here I’ve used a 40GB but you can choose what you want. and the second needs to be al least 15GB to copy all the image parts, as the tool imagex doesn’t prompt for multi-disk image and we need to do this manually. I wouldn’t be too worried by now about the size of the partitions. I my case, once I had the system restored and Windows finished installing, I went to the Windows Disk Management tools and I resized the Windows partition and created some Striped partitions (RAID 0) to improve performance.</p>
<p>In case you need to use Windows HD encryption, you will need to create 3 partitions. 1st for the partition called “system” (this one will be the active one, and it doesn’t need a letter assigned as it’s hidden)</p>
<p>After booting from the boot DVD you will have a command prompt. </p>
<p>Type: <strong><em>diskpart</em></strong></p>
<p><em><strong>SELECT DISK 0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />CLEAN&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </strong></em></p>
<p><strong><em>CREATE PARTITION PRIMARY SIZE=40000</em>&#160;&#160;&#160;&#160;&#160;&#160; </strong><font color="#008000"><strong>(create a 40GB partition for Windows)        <br /></strong></font><strong><em>SELECT PARTITION 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />FORMAT QUICK FS=NTFS LABEL=&quot;Windows&quot;         <br />ASSIGN LETTER=&quot;C&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />ACTIVE</em> </strong></p>
<p><em><strong>CREATE PARTITION PRIMARY&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000">(create a second partition in the disk for the remaining)</font>         <br />SELECT PARTITION 2&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />FORMAT QUICK FS=NTFS LABEL=&quot;EXT&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />ASSIGN LETTER=&quot;e&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </strong></em></p>
<p><em><strong>EXIT</strong></em></p>
<p>&#160;</p>
<h1><font color="#000080">Copy image parts to disk</font></h1>
<p>Now that we have the partitions we need to copy the image parts and the tool to restore the image to e:</p>
<p>In case you had the image parts in an external HD or USB Key or the second HD, you don’t need to copy the files locally. Instead you could connect your USB external HD and go to the next step (restore the image) because the system can detect the external HD when you plug it in and read the image directly from there (you only need to type the right source location)</p>
<p><strong><em>copy d:\imagex.exe e:\</em></strong></p>
<p><strong><em>copy d:\sources\asus.swm e:\</em></strong></p>
<p><font color="#008000">(change to DVD 2 )</font></p>
<p><strong><em>copy d:\sources\asus2.swm e:\</em></strong></p>
<p><font color="#008000">(change to DVD 3 )</font></p>
<p><em><strong>copy d:\sources\asus3.swm e:\</strong></em></p>
<p><strong><em></em></strong></p>
<p>&#160;</p>
<h1><font color="#000080">Restore the image</font></h1>
<p>Once we have the files in the HD e:, we need to go to e: (where we have the imagex.exe file) and apply the image to the HD c: with the next command</p>
<p><strong><em>e:        <br />imagex /ref e:\asus*.swm /apply e:\asus.swm 1 c:</em></strong></p>
<p>The command:</p>
<ul>
<li>/ref e:\asus*.swm&#160;&#160; =&gt; <font color="#008000">tells the imagex program that the file is in several parts and needs to reference all the files called e:\asus*.swm </font></li>
<li>/apply e:\asus.swm 1 c:&#160; =&gt; <font color="#008000">tells the imagex program that the file to apply is called e:\asus.swm (to create that file uses the /ref files) and it needs to apply from that file the image number 1 (because the tools support several images in a single file) to the HD called C: </font></li>
</ul>
<p>This process can take a while, just wait until it’s finished.</p>
<p>&#160;</p>
<h1><font color="#000080">Make the HD bootable</font></h1>
<p>Now that the Windows image has been restored we need to make that image bootable. To do that we need to go the the restored Windows system files and run the bcdboot command.</p>
<p><strong><em>CD c:\Windows\System32        <br />BCDBOOT C:\Windows</em></strong></p>
<p>&#160;</p>
<h1><font color="#000080">Finished!</font></h1>
<p>At this stage your system has already been restored and you need to reboot. Remove all your DVDs and restart the machine.</p>
<p>You can type <strong><em>wpeutil reboot</em></strong> to do so.</p>
<p>If everything went Ok, your system must be restarting and finishing the installation in the same way it did the first day that you used your computer. So finish the install, fix your partitions and uninstall all the rubbish that thy have installed by default. I also recommend to create a backup of your system once you have it the way you like it, and next time you can restore it to that state directly without having to do all these steps.</p>
<p>&#160;</p>
<h1><font color="#004000">The scripts</font></h1>
<p>To finish creating the fully automated restore you can use the following scripts (to continue the process in the <a href="http://rmencia.wordpress.com/2010/07/07/creating-windows-oem-recovery-dvds-with-windows-aik-part-1">part 1</a>). </p>
<p>There are 2 txt files with the commands for diskpart to clean the HD and create partitions. The reason why is that depending on the HD partitions before restoring the system, when the restoring starts, the partitions are mounted in different drive letters. If this happens, the scripts don’t know which drive contains the tools and where to copy the image files. To solve that, what I have implemented is a 2 steps recovery. First, I check if the tools are in the expected location (it happens when the HD is clean). If the script can’t find the tools in the HD d:, then cleans the HD and restarts automatically. Next time the system boots, we know where we are and we can automate the process. There are better ways to do this, but this one works and I didn’t want to spend too long for a process that shouldn&#8217;t happen more than once or twice a year.</p>
<p>&#160;</p>
<h3><font color="#004000">Diskpart clean HD (clear_partitions.txt)</font></h3>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<p>SELECT DISK 0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />CLEAN&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>EXIT</p>
</td>
</tr>
</tbody>
</table>
<p><a href="http://rmencia.files.wordpress.com/2010/07/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://rmencia.files.wordpress.com/2010/07/image_thumb2.png?w=259&#038;h=161" width="259" height="161" /></a> </p>
<p>&#160;</p>
<h3><font color="#004000">Diskpart clean HD (create_partitions.txt)</font></h3>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<p>SELECT DISK 0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />CLEAN&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>CREATE PARTITION PRIMARY SIZE=40000&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />SELECT PARTITION 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />FORMAT QUICK FS=NTFS LABEL=&quot;Windows&quot;             <br />ASSIGN LETTER=&quot;C&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />ACTIVE </p>
<p>CREATE PARTITION PRIMARY&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />SELECT PARTITION 2&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />FORMAT QUICK FS=NTFS LABEL=&quot;EXT&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />ASSIGN LETTER=&quot;e&quot;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>EXIT</p>
</td>
</tr>
</tbody>
</table>
<p><a href="http://rmencia.files.wordpress.com/2010/07/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://rmencia.files.wordpress.com/2010/07/image_thumb3.png?w=334&#038;h=263" width="334" height="263" /></a> </p>
<p>&#160;</p>
<h3><font color="#004000">Restore.cmd</font></h3>
<p>In this script I have added a bit of error checking, some CLS (clear screen) and messages to make it look a bit better and easier to use once it’s been deployed.</p>
<p>You can modify the script to adapt it you your convenience in case you have a different number of DVDs or you are creating images for other machines.</p>
<ol>
<li>The first section I check if the tools are where I expect. If they aren’t I clean the HD and I restart (I have explained this above). </li>
<li>In the second section I check if the *.swm files are where I expect. If they aren’t I prompt to change the disk and try again. When you change the disk, some times it takes a couple of seconds for the system to pick it up, so be patient. </li>
<li>After the files are copied I copy imagex to e: and start restoring </li>
<li>Then I create the boot for the new Windows </li>
<li>And I restart. I used the command ping to wait for 5 seconds and let the user see that it’s all good, but you can remove this step (ping -n 6 127.0.0.1 &gt; nul&#160; each ping take 1 second) </li>
<li>If there was any error I jump to the end and I finish the process </li>
</ol>
<table border="1" cellspacing="0" cellpadding="2" width="668">
<tbody>
<tr>
<td valign="top" width="666">
<p>@echo off            <br />CLS             <br /><strong>@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;              <br />@echo.&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Initializing Hard Drive               <br />@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</strong>             <br />@echo. </p>
<p>IF NOT EXIST d:\create_partitions.txt (            <br />&#160;&#160;&#160; @echo. Cleaning the HD and rebooting afterwards             <br />&#160;&#160;&#160; diskpart /s clear_partitions.txt </p>
<p>&#160;&#160;&#160; wpeutil Reboot            <br />) </p>
<p>@echo. Initialising the HD            <br />diskpart /s d:\create_partitions.txt </p>
<p>if errorlevel 1 goto :errorPartitions </p>
<p>copy d:\imagex.exe e:\ </p>
<p>CLS            <br /><strong>@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;              <br />@echo.&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Copying the images from DVD               <br />@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</strong>             <br />@echo. </p>
<p>:retryFile1            <br />IF NOT EXIST d:\sources\asus.swm (             <br />&#160;&#160;&#160; @echo.             <br />&#160;&#160;&#160; @echo. File not found d:\sources\asus.swm             <br />&#160;&#160;&#160; @echo. Insert the DVD 1 and wait 5 secs. until DVD is loaded             <br />&#160;&#160;&#160; @echo.             <br />&#160;&#160;&#160; pause             <br />&#160;&#160;&#160; goto :retryFile1             <br />)             <br />@echo.             <br />@echo. Copying DVD 1 (d:\sources\asus.swm)             <br />copy d:\sources\asus.swm e:\             <br />if errorlevel 1 goto :retryFile1 </p>
<p>CLS            <br />:retryFile2             <br />@echo. Insert the DVD 2 and wait 5 secs. until DVD is loaded             <br />pause             <br />IF NOT EXIST d:\sources\asus2.swm (             <br />&#160;&#160;&#160; @echo.             <br />&#160;&#160;&#160; @echo. File not found d:\sources\asus2.swm in DVD 2             <br />&#160;&#160;&#160; goto :retryFile2             <br />)             <br />@echo.             <br />@echo. Copying DVD 2 (d:\sources\asus2.swm)             <br />copy d:\sources\asus2.swm e:\             <br />if errorlevel 1 goto :retryFile2 </p>
<p>CLS            <br />:retryFile3             <br />@echo. Insert the DVD 3 and wait 5 secs. until DVD is loaded             <br />pause             <br />IF NOT EXIST d:\sources\asus3.swm (             <br />&#160;&#160;&#160; @echo.             <br />&#160;&#160;&#160; @echo. File not found d:\sources\asus3.swm in DVD 3             <br />&#160;&#160;&#160; goto :retryFile3             <br />)             <br />@echo.             <br />@echo. Copying DVD 3 (d:\sources\asus3.swm)             <br />copy d:\sources\asus3.swm e:\             <br />if errorlevel 1 goto :retryFile3 </p>
<p>CLS            <br /><strong>@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;              <br />@echo.&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Restoring image to drive C:               <br />@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</strong>             <br />@echo. </p>
<p>e:            <br />imagex /ref e:\asus*.swm /apply e:\asus.swm 1 c: </p>
<p>if errorlevel 1 goto :errorRestore </p>
<p>CLS            <br /><strong>@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;              <br />@echo.&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Setting up boot partition               <br />@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</strong>             <br />@echo. </p>
<p>CD c:\Windows\System32            <br />BCDBOOT C:\Windows </p>
<p>if errorlevel 1 goto :errorBoot </p>
<p>CLS            <br /><strong>@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;              <br />@echo.&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Process Finished!               <br />@echo.&#160;&#160;&#160;&#160;&#160; The system will reboot in 5 seconds               <br />@echo. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</strong>             <br />@echo.             <br />ping -n 6 127.0.0.1 &gt; nul </p>
<p>wpeutil reboot </p>
<p>:errorPartitions            <br />@echo. There was an error cleaning the hard disk and creating the partitions.             <br />goto :end </p>
<p>:errorRestore            <br />@echo. There was an error restoring the image.             <br />goto :end </p>
<p>:errorBoot            <br />@echo. There was an error creating the boot.             <br />goto :end </p>
<p>:end</p>
</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<h1>Congratulations!</h1>
<p>At this stage you are smarter than the guys that developed the restoring system for ASUS because:</p>
<ul>
<li>you understand all the recovery process (the tech support has no idea and they will tell you that you can’t be happy and that you need to take the computer for them to restore it and waste your time for few hours) </li>
<li>you are able to create a more flexible set of recovering disks (ASUS want you to be unhappy trying to restrict you how to use the computer that you have bought) </li>
<li>You no longer have a 20GB partition in your HD. </li>
</ul>
<p>If ASUS was smarter, they would give you the original install install disk (I would have paid a bit extra to avoid all the crap that they have put in my computer and that I have uninstalled anyways). They may probably get some extra cash from the companies of the preinstalled rubbishware they put in your machine, but in a long term, they end up paying back all that money because of they need a larger number of people in support to attend complains and answering users and they have to spend extra resources as electricity to keep your computer plugged-in while restoring. </p>
<p>&#160;</p>
<p>Enjoy your coffee!!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=118&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2010/07/09/creating-windows-oem-recovery-dvds-with-windows-aik-part-2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2010/07/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2010/07/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating Windows OEM recovery DVDs with Windows AIK (part 1)</title>
		<link>http://rmencia.wordpress.com/2010/07/07/creating-windows-oem-recovery-dvds-with-windows-aik-part-1/</link>
		<comments>http://rmencia.wordpress.com/2010/07/07/creating-windows-oem-recovery-dvds-with-windows-aik-part-1/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 02:53:53 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[Windows AIK]]></category>
		<category><![CDATA[WAIK]]></category>

		<guid isPermaLink="false">https://rmencia.wordpress.com/2010/07/07/creating-windows-oem-recovery-dvds-with-windows-aik-part-1/</guid>
		<description><![CDATA[This post follows the previous post in were I explained how I bought a new ASUS laptop with preinstalled Windows 7 PRO x64 OEM and they didn’t give me the restore DVDs. Instead they had a retarded restoring system that relied on a 20GB partition in the HD that got useless when I changed my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=111&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post follows the previous post in were I explained how I bought a new ASUS laptop with preinstalled Windows 7 PRO x64 OEM and they didn’t give me the restore DVDs. Instead they had a retarded restoring system that relied on a 20GB partition in the HD that got useless when I changed my Partitions to use the Striped and Mirror features that come with the OS.</p>
<p>In this post I’ll explain how to manually create a set of DVDs from the original ASUS system image files named <em>asus.swm</em>, <em>asus2.swm</em> and <em>asus3.swm</em>. This method can be used for other brands that have the same type of lame restoring system or if you want to split an image bigger than the size of a DVD (usually the split is named <em>install.swm install2.swm install3.swm</em>).</p>
<p>After you finish reading your post you’ll be able to create a set of DVDs/CDs of the size you want and have a bootable DVD/CD that will automate the restoring and prompting to introduce the next disk. I’m going to add as many details and explanations as I can to allow non developers to be able to understand the process and create their set of DVDs. So if you find it too easy, skim through. If you find it still complicated, add a comment and I’ll try to give more samples (you can read the MS documentation as well).</p>
<p>To create the recovery DVDs we are going to need “<a href="http://technet.microsoft.com/en-us/library/dd349343%28WS.10%29.aspx">Windows Automated Installation Kit for Windows 7</a>” (Windows 7 AIK) installed (you can download it and install it for free). This is the set of tools that the laptop manufacturers use create the images that are installed in your system. This post can also be used as a tutorial to understand the process of deployment using Windows 7 AIK (the steps used here are taken out from Microsoft documentation and they are using the tools that MS has made freely available to users to deploy Windows in an alternative way to standard setup). I take no responsibility of any errors in the scripts that I’ll be providing in the next post and I take no responsibility of the information that could be lost by using these steps. Please take your time to read the official Microsoft documentation about the tools and the risks of using them (<a href="http://technet.microsoft.com/en-us/library/dd744356%28WS.10%29.aspx">http://technet.microsoft.com/en-us/library/dd744356%28WS.10%29.aspx</a>) and remember that restoring the image will wipe out all the data in your HD so you need to run a backup of your data before you restore your system. And remember that these instructions should never be used to install Windows in a computer other to the one that you have paid the license for (no license no install). Please read read your Windows license agreement before following the steps to install your Windows image.</p>
<h1>Lets get started!</h1>
<p>Before we start with the process ne need to have the full image file (install.wim or asus.wim or image.wim) or the image already split in parts (<em>asus.swm</em>, <em>asus2.swm</em> and <em>asus3.swm</em> or <em>install.swm install2.swm install3.swm</em>). If you want to change the size to use double layer DVDs or CDs or a Blu-Ray or any other thing, you can join your image and then split it back in the size that you want. To do that you can use <a href="http://technet.microsoft.com/en-us/library/cc722145%28WS.10%29.aspx">imagex</a> command to:</p>
<p><a href="http://technet.microsoft.com/en-us/library/dd799251%28WS.10%29.aspx">Split an image file</a>:</p>
<ul>
<li><strong><em>imagex /split C:\imaging\asus.wim D:\imaging\asus.swm 4000</em></strong></li>
<li><strong><em>imagex /split C:\imaging\install.wim D:\imaging\install.swm 4000</em></strong></li>
</ul>
<p><a href="http://technet.microsoft.com/en-us/library/cc749447%28WS.10%29.aspx">Join an image file</a>:</p>
<ul>
<li><strong><em>imagex /ref asus*.swm /check /export asus.swm 1 asus.wim</em></strong></li>
<li><strong><em>imagex /ref install*.swm /check /export install.swm 1 install.wim</em></strong></li>
</ul>
<p>Now that we have our images with the size that we want, we are going to start.</p>
<h2>Create a bootable DVD to start the process</h2>
<p>To restore the system we need to create a bootable DVD with all the tools required to boot, configuration files to create partitions and scripts to restore the image.</p>
<p>In this process I will assume that we have installed Win AIK in the standard path (c:) and that we want to do the work in the d: drive.</p>
<ol>
<li>Start Windows AIK command line <strong>as an administrator</strong><a href="http://rmencia.files.wordpress.com/2010/07/image.png"></a></li>
<p><a href="http://rmencia.files.wordpress.com/2010/07/image.png"><img style="display:inline;border-width:0;" title="image" src="http://rmencia.files.wordpress.com/2010/07/image_thumb.png?w=244&#038;h=100" border="0" alt="image" width="244" height="100" /></a></p>
<li>Get the required files for the boot DVD (boot image with standard MS tools)
<ul>
<li><strong><em>copype.cmd x86 d:\winpe_x86</em></strong></li>
</ul>
</li>
<li>Mount the image to add custom restore scripts (this is similar to mounting an ISO but here we use a folder for you to modify the files)
<ul>
<li><strong><em>imagex.exe /mountrw d:\winpe_x86\winpe.wim 1 d:\winpe_x86\mount</em></strong></li>
<li>mount <strong><em>winpe.wim</em></strong> (MS boot image) in the folder that we specify)</li>
</ul>
</li>
<li>In this step we will copy the restore script and the commands to re create the disk partitions (I’ll explain this later in the <a href="http://rmencia.wordpress.com/2010/07/09/creating-windows-oem-recovery-dvds-with-windows-aik-part-2/" target="_blank">next post</a>). However, with the DVDs you can already manually restore your system once you boot with the first restoring disk (the process requires to create 2 partitions, 1 for Windows and 1 to copy the *swm files)
<ul>
<li>
<ul>
<li>restore.cmd: script to restore the system automatically</li>
<li>clear_partitions.txt: Cleans the Hard drive</li>
<li>create_partitions.txt: Creates the partitions before restoring the image</li>
</ul>
</li>
<p><strong><em>copy restore.cmd d:\winpe_x86\mount\Windows\System32\<br />
copy clear_partitions.txt d:\winpe_x86\mount\Windows\System32\<br />
copy create_partitions.txt d:\winpe_x86\mount\Windows\System32\</em></strong></ul>
</li>
<li>Modify startup to call our restore script (This step required opening notepad as administrator. You can launch it from an Administrator command line)
<ul>
<li><strong><em>notepad.exe d:\winpe_x86\mount\Windows\System32\System32\startnet.cmd</em></strong></li>
<li><strong>startnet.cmd</strong> is the script the is executed when booting the DVD. We need to add an extra line at the end of the file to call our <strong>restore.cmd</strong> script <a href="http://rmencia.files.wordpress.com/2010/07/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://rmencia.files.wordpress.com/2010/07/image_thumb1.png?w=244&#038;h=98" border="0" alt="image" width="244" height="98" /></a></li>
<li>What we have done here is to call our script to start the restoring process. This allows us to create an automated restoring process for simplicity.</li>
</ul>
</li>
<li>Save the changes in the customized image (commit the changes to the mounted boot image)<strong><em>imagex.exe /unmount /commit d:\winpe_x86\mount</em></strong><em><br />
imagex.exe /unmount d:\winpe_x86\mount<br />
imagex.exe /unmount /cleanup</em><strong><em>Note:</em></strong> For some reason, sometimes the first command sometimes doesn’t do all the work and there are files still hanging around. Most likely the command has <strong>successfully</strong> updated the image but it can’t unmount and release the files. If this happens, you need to close all the Windows Explorer windows and run the second and third commands (some times even several times) until “imagex.exe /unmount /cleanup” tells you that nothing is mounted.</li>
<li>Create the DVD folders (each folder will be one DVD)Create folders:<br />
<strong><em>d:\ASUS\DVD1\sources</em></strong> (this will be the bootable DVD)<br />
<strong><em>d:\ASUS\DVD2\sources</em></strong><br />
<strong><em>d:\ASUS\DVD3\sources</em></strong><strong><em>copy asus.swm d:\ASUS\DVD1\sources<br />
copy asus2.swm d:\ASUS\DVD2\sources<br />
copy asus3.swm d:\ASUS\DVD3\sources</em></strong></li>
<li>Add extra required tools to DVD1 to make the DVD bootable and copy the program used to restore the system<strong><em>xcopy /y /e d:\winpe_x86\ISO\*.* e:\ASUS\DVD1\ </em></strong><strong><em>copy &#8220;C:\Program Files\Windows AIK\Tools\x86\imagex.exe&#8221; d:\ASUS\DVD1\</em></strong></li>
<li>Copy customized boot to DVD1 (created in step 6)
<ul>
<li><strong><em>copy d:\winpe_x86\winpe.wim d:\ASUS\DVD1\sources\boot.wim</em></strong></li>
<li>Notice the change of name. The destination name <strong>must</strong> be <em>boot.wim</em></li>
</ul>
</li>
<li>Create the disk images (notice that the first one is bootable)<strong><em>oscdimg -m -n -b&#8221;d:\winpe_x86\etfsboot.com&#8221; D:\ASUS\DVD1 D:\ASUS\DVD1.iso </em></strong><strong><em>oscdimg -m -n D:\ASUS\DVD2 D:\ASUS\DVD2.iso </em></strong><strong><em>oscdimg -m -n D:\ASUS\DVD3 D:\ASUS\DVD3.iso</em></strong></li>
<li>Burn images to DVDs (with Windows 7 right click on the ISO and choose burn)</li>
<li>Congratulations! You have created your set of restoring DVDs.</li>
</ol>
<p>In the <a href="http://rmencia.wordpress.com/2010/07/09/creating-windows-oem-recovery-dvds-with-windows-aik-part-2/" target="_blank">next post</a> I’ll explain how to fully automate the process creating the scripts from the step 4.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=111&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2010/07/07/creating-windows-oem-recovery-dvds-with-windows-aik-part-1/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2010/07/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2010/07/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>I learnt Windows AIK because of my new ASUS Laptop</title>
		<link>http://rmencia.wordpress.com/2010/06/29/i-learnt-windows-aik-because-of-my-new-asus-laptop/</link>
		<comments>http://rmencia.wordpress.com/2010/06/29/i-learnt-windows-aik-because-of-my-new-asus-laptop/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 05:58:25 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[Windows AIK]]></category>
		<category><![CDATA[WAIK]]></category>

		<guid isPermaLink="false">https://rmencia.wordpress.com/2010/06/29/restore-your-computer-using-windows-aik/</guid>
		<description><![CDATA[I’ve recently bought a new ASUS G73jh Laptop. It’s a wonderful piece of HW with a Intel i7 720QM, 8GB RAM, 2x500GB HD, ATI HD5870 and Windows 7 PRO x64. The only problem is that ASUS (same as other laptop assemblers) has gone into the path of installing the operating system with a bunch of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=102&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve recently bought a new ASUS G73jh Laptop. It’s a wonderful piece of HW with a Intel i7 720QM, 8GB RAM, 2x500GB HD, ATI HD5870 and Windows 7 PRO x64.</p>
<p>The only problem is that ASUS (same as other laptop assemblers) has gone into the path of installing the operating system with a bunch of applications that are totally irrelevant to the work that I want to do (some people call it <a href="http://www.urbandictionary.com/define.php?term=crapware">crapware</a> or more politely <a href="http://en.wikipedia.org/wiki/Pre-installed_software">pre-installed sw</a>).</p>
<p>This common practice would be ok if I was able to reinstall my computer in a clean way, however ASUS doesn’t provide a clean way to install the copy of Windows 7 that I have paid for. Instead, they have created a 20GB partition in the first HD that contains the recovery files. But guess what happens if you want to install your own SSD or you enable stripped volumes in Windows?</p>
<p>They allow you to create a set of DVDs with a tool in a very easy way (6 DVDs said in my case). But, before creating them, I went to play with the Disk Management and changed the partitions to look the way I wanted with stripped and mirror volumes. When I went to create the recovery DVDs… the tool failed even when the RECOVERY partition was still there because the type of disk had changed from Basic to Dynamic (in the documentation they don’t explain all this).</p>
<p>I wrote to get technical support and after 3 days they answered with this:</p>
<p><em><span style="color:#000080;">Dear Valued Customer,<br />
Thank you for contacting ASUS Customer Service.<br />
Good morning, unfortunately, all our notebooks are preinstalled with OEM version of OS and don&#8217;t equip with the install DVD. <strong>If you want to do a clean install, I am afraid you have to purchase the installation disc from Microsoft separately</strong>.</span></em></p>
<p>So basically, get lost.</p>
<p>I answered to their email, really pissed off, saying that that didn’t help me at all and they answered back:</p>
<p><em><span style="color:#000080;">Dear Valued Customer,<br />
Thank you for contacting ASUS Customer Service.<br />
Sorry, the notebook product package will not come with the RCD(Recovery CD) and ASUS DVD 6 in 1 from 2/4, please refer to the following page:<br />
</span></em><a href="http://support.asus.com/news/news.aspx?no=595&amp;SLanguage=en-us"><em><span style="color:#000080;">http://support.asus.com/news/news.aspx?no=595&amp;SLanguage=en-us</span></em></a><br />
<em><span style="color:#000080;">If you need a recovery DVD, please contact ASUS on 1300 278 788 from Monday to Friday between 9 am and 6 pm AEST.<br />
<strong>As for the AI Recovery, we are aware of an issue with the AI Recovery Burner not functioning correctly and are currently investigating the matter.</strong> This issue does not affect the normal operatin of the notebook in anyway.<br />
We apologise for any inconvenience caused as a result of this issue.</span></em></p>
<p>That’s even better!!! They have a tool to create recovery DVDs and it doesn’t work. I called the service and they actually were quite nice and they told me that I could go any time and they would restore the system to the original state without any problem. However, that would not help me much if I couldn’t set up the system the way I wanted.</p>
<p>I am EXTREMELY disappointed in ASUS and I feel that for them it is more important to make money than keeping the clients happy. I will never consider buying any more laptops from ASUS unless they change their strategy of control over the clients, even if I think that their HW is good.</p>
<p>To solve all these problems and to get rid of the RECOVERY (also called 20GB wasted space in my disk) I started investigating to see what these asus.swm, asus2.swm and asus3.swm files were. And after some reading I ended up installing “<a href="http://technet.microsoft.com/en-us/library/dd349343%28WS.10%29.aspx">Windows Automated Installation Kit for Windows 7</a>” or (Windows 7 AIK).</p>
<p>With that set of tools, Microsoft allows OEM installers to POLLUTE the brand new computers (of FREE users that have paid for the Windows license) with an incredible amount of useless applications and not allowing the right to decide what applications we want to have in our clean system. So you are forced to waste 2 hours in front of the computer uninstalling unwanted pollution.</p>
<blockquote><p><em><strong>Note:</strong> After all the hard work, I recommend to uninstall all the applications that you don’t want and use. Do all the work in the partitions that you need and run Windows 7 Back up tools to create an image into either an external HD, DVDs or the network. Then you can create a system repair disk and every time you need to restore Windows to a clean state you can go directly to this image backup and get everything up and running in few minutes and without all the “pre-installed” trial applications.</em></p></blockquote>
<p>Anyways, to solve this issue I’ve been working in a solution to make users a bit more free and I will be posting it soon.</p>
<p>1. The first solution I’ve been working on is for people that:</p>
<ul>
<li>They still have the RECOVERY partition but it’s not bootable anymore and they can’t create a set of recovery DVDs</li>
<li>They want to delete the 20GB RECOVERY partition</li>
<li>They want to use Dynamic disks in Windows (stripped and mirrored)</li>
<li>They want to install an SSD as a primary disk</li>
<li>It uses 3 DVDs</li>
</ul>
<p>2. I’ll be working in creating an image of Windows with the Out Of The Box experience but that doesn’t contain any pre-installed applications (or forced to have applications)</p>
<ul>
<li>The steps will be very similar to the first solution but you’ll get a smaller version (maybe 1 or 2 DVDs)</li>
<li>I haven’t tried this but I hope it can be done.</li>
</ul>
<p>All this is only to allow the owner of the computer that has paid for the Windows 7 License to create a more free way of installing it’s own computer or a way to create a system backup in case of system failure.</p>
<p>These instructions should never be used to install Windows in a computer other to the one that you have paid the license for (no license no install). Please read read your Windows license before following the steps.</p>
<p>It can be used as a tutorial to understand the process of deployment using Windows 7 AIK (the steps used here are taken out from Microsoft documentation and they are using the tools that MS has made freely available to users to deploy Windows in an alternative way to standard setup).</p>
<p>I take no responsibility of any errors in the scripts that I’ll be providing in the next post and I take no responsibility of the information that could be lost by using these steps. Please take your time to read the official Microsoft documentation about the tools and the risks of using them (<a title="http://technet.microsoft.com/en-us/library/dd744356%28WS.10%29.aspx" href="http://technet.microsoft.com/en-us/library/dd744356%28WS.10%29.aspx">http://technet.microsoft.com/en-us/library/dd744356%28WS.10%29.aspx</a>)</p>
<p>Use the next post at your own risk.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=102&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2010/06/29/i-learnt-windows-aik-because-of-my-new-asus-laptop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>
	</item>
		<item>
		<title>Federated SignIn Requires Federated SignOut</title>
		<link>http://rmencia.wordpress.com/2010/05/05/federated-signin-requires-federated-signout/</link>
		<comments>http://rmencia.wordpress.com/2010/05/05/federated-signin-requires-federated-signout/#comments</comments>
		<pubDate>Wed, 05 May 2010 05:22:34 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[WIF]]></category>
		<category><![CDATA[Claims]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[SecurityToken]]></category>
		<category><![CDATA[Token]]></category>

		<guid isPermaLink="false">https://rmencia.wordpress.com/2010/05/05/federation-signin-requires-federation-signout/</guid>
		<description><![CDATA[Using WIF and a Passive STS is cool, but it’s even cooler when your Passive STS is in a different machine. Now that we have Federation SignIn and a Passive STS that lives in a Different box and all out web apps rely on that external STS… How can I sign out? In my case [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=94&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Using WIF and a Passive STS is cool, but it’s even cooler when your Passive STS is in a different machine.</p>
<p>Now that we have Federation SignIn and a Passive STS that lives in a Different box and all out web apps rely on that external STS… How can I sign out?</p>
<p>In my case I tried everything and of course, it worked in my machine. Then it got deployed and the user didn’t get signed out because the browser didn’t expire the WIF token.</p>
<p>I executed all this and custom code to make the cookies expire but there was one left, the one created by the STS.<br />
<pre class="brush: csharp;">
FederatedAuthentication.SessionAuthenticationModule.SignOut();
FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie();
FederatedAuthentication.WSFederationAuthenticationModule.SignOut(false);
FormsAuthentication.SignOut();
</pre><br />
Bloody cookie, die!!! But nothing. The browser wouldn’t expire it and then it all made sense, I can’t make expire cookies that I haven’t created myself. So I thought that there would be a solution to this and I run all this without any luck. I checked the WIF doco, I Goggled it with Bing and nothing.</p>
<p>Finally I found a reference to something and of course NO SAMPLES (Isn’t WIF wonderfull!!!)</p>
<p>The solution is using the FederatedSignOut method that redirects to the STS, this one signs you out and redirects the browser to the page that you wanted to go to let the user know that he’s out.<br />
<pre class="brush: csharp;">
WSFederationAuthenticationModule authModule = FederatedAuthentication.WSFederationAuthenticationModule;
string signoutUrl = (WSFederationAuthenticationModule.GetFederationPassiveSignOutUrl(authModule.Issuer, authModule.Realm, null));
WSFederationAuthenticationModule.FederatedSignOut(new Uri(authModule.Issuer), new Uri(authModule.Realm + &quot;LoggedOut.html&quot;));
</pre><br />
It’s up to you to find out how to solve the new issue, the redirection to LoggedOut.html sends you back to the Login page in the STS because you where logged out (this is good fun if you use Windows Authentication because you get logged in again without knowing it.</p>
<p>The second catch is… once you are in the LoggedOut.html page, press the back button in the browser <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Have fun</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=94&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2010/05/05/federated-signin-requires-federated-signout/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>
	</item>
		<item>
		<title>Serializing/Deserializing the bootstrap token</title>
		<link>http://rmencia.wordpress.com/2010/03/30/serializingdeserializing-the-bootstrap-token/</link>
		<comments>http://rmencia.wordpress.com/2010/03/30/serializingdeserializing-the-bootstrap-token/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 23:39:22 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[Identity]]></category>
		<category><![CDATA[WIF]]></category>
		<category><![CDATA[Certificates]]></category>
		<category><![CDATA[Claims]]></category>
		<category><![CDATA[Deserialization]]></category>
		<category><![CDATA[SecurityToken]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[Token]]></category>

		<guid isPermaLink="false">http://rmencia.wordpress.com/2010/03/30/serializingdeserializing-the-bootstrap-token/</guid>
		<description><![CDATA[I’ve been doing some work with WCF and WIF. Yes this new foundation thing called Windows Identity Foundation. If you have seen the PDC09 demos than you probably thought that it’s so easy to add security to an application… well yes and no. It’s easy if you only want the standard functionality out of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=80&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve been doing some work with WCF and WIF. Yes this new foundation thing called <em>Windows Identity Foundation</em>.</p>
<p>If you have seen the PDC09 demos than you probably thought that it’s so easy to add security to an application… well yes and no. It’s easy if you only want the standard functionality out of the box, but if you need to do something different… it’s quite complicated to get everything working. However, once you understand what’s going on then it is a lot smoother and you don’t need to worry anymore about how it works, it just works.</p>
<p>The last tornado I had to deal with was the serialization of security tokens. You may want to know why you would want to serialize tokens if WIF does it for you adding them to cookies or WCF heathers. Well that’s like asking why you would generate plain HTML to add custom CSS when you can use ASP.Net controls that spit out heaps of formatted html with colors. In this case, my reason is that I wanted to be able to open a windows application from the web browser and keeping the credentials I had in the browser.</p>
<p>To do that, you need to serialize the token into a file and your browser opens the application associated to that extension. It’s like when you download an excel sheet and instead of saving the file you open it directly in Excel or the same with a PDF. But in our scenario, we send the information that WIF had put in a cookie to the windows app so that we can call some WCF services. Easy. Serialize that monster and you deserialize it in the client to create the Channel. Go for it. If you are reading this is because it wasn’t that easy, isn’t it? Then, try to deserialize it now that you managed to serialize it. Ha!!.</p>
<p>The Idea is that you serialise your bootstrap token into an XML string</p>
<p><pre class="brush: csharp;">

var bootstrapToken = ((IClaimsPrincipal)Thread.CurrentPrincipal).Identities[0].BootstrapToken; 

// Serialize
var req = new SamlSecurityTokenRequirement();
var handler = new Saml11SecurityTokenHandler(req);
var sb = new StringBuilder();
using (var writer = XmlWriter.Create(sb))
{
   handler.WriteToken(writer, bootstrapToken);                   
}

string serializedToken = sb.ToString();

</pre></p>
<p>Serializarion is quite simple, but to deserialize the token we need to have the public key of the signing certificate because the classes that do the deserialization want to validate that <strong>moster</strong>. This sample shows how to read the certificate from a file, but the constructors allow reading from a stream (or you may want to serialize the x509 certificate together with the token in the file that you send to your win app).</p>
<p><pre class="brush: csharp;">
// Deserialize
string path = @&quot;c:\temp\STSPublic.cer&quot;;
// It can be deserialised from a byte[]
var cert = new X509Certificate2(path);
var token = new X509SecurityToken(cert);
var tokens = new List&lt;SecurityToken&gt;() {token}; 

var resolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(tokens.AsReadOnly(), false);
var conf = new SecurityTokenHandlerConfiguration();
conf.IssuerTokenResolver = resolver;
handler.Configuration = conf; 

using (var reader = XmlReader.Create(new StringReader(sb.ToString())))
{
   bootstrapToken2 = handler.ReadToken(reader);
}

</pre></p>
<p>Instead of reading the certificate from a file you can read the certificate from the list of installed certificated from the local machine you can also use the following code.</p>
<p><pre class="brush: csharp;">

var token = new X509SecurityToken(CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, &quot;CN=STSCertificateName&quot;));

</pre></p>
<p>Now it’s up to you to do whatever you want with the token in the windows app.</p>
<p>I hope this helps.</p>
<p>R.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=80&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2010/03/30/serializingdeserializing-the-bootstrap-token/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>
	</item>
		<item>
		<title>Source control error in VS2008 and Windows 7 x64</title>
		<link>http://rmencia.wordpress.com/2009/08/10/source-control-error-in-vs2008-and-windows-7-x64/</link>
		<comments>http://rmencia.wordpress.com/2009/08/10/source-control-error-in-vs2008-and-windows-7-x64/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 05:06:02 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://rmencia.wordpress.com/2009/08/10/source-control-error-in-vs2008-and-windows-7-x64/</guid>
		<description><![CDATA[I have installed Windows 7 x64 RTM in my work machine and… Surprise! Team Explorer wouldn’t work. The settings were disabled and when I tried to connect to a server BOOOOOM! &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Microsoft Visual Studio &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Unexpected error encountered. It is recommended that you restart the application as soon as possible. Error: Access is denied. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=78&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have installed Windows 7 x64 RTM in my work machine and… Surprise! Team Explorer wouldn’t work.</p>
<p>The settings were disabled and when I tried to connect to a server BOOOOOM!</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400"> 
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;           <br />Microsoft Visual Studio            <br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;            <br />Unexpected error encountered. It is recommended that you restart the application as soon as possible. </p>
<p>Error: Access is denied. </p>
<p>File: vsee\pkgs\vssproviderstub\cvssproviderstubpackage.cpp </p>
<p>Line number: 528           <br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;            <br />OK&#160;&#160; <br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>This is the kind of errors that I love.</p>
<p>After uninstalling and installing and reinstalling and again installing VS2008 and Team Client and… nothing worked.</p>
<p>Finally, after searching everywhere, I found in the msdn forums someone that had a similar problem. What a relieve, I wasn’t the only one (it seems a smaller problem when you aren’t the only one with it).</p>
<p>As a solution, <a href="http://social.msdn.microsoft.com/Profile/en-US/?user=K.%20Renno&amp;referrer=http%3a%2f%2fsocial.msdn.microsoft.com%2fForums%2fen-US%2fvssourcecontrol%2fthread%2fb5a750af-088f-4981-ac24-5b6ee91d2233&amp;rh=ExK8n4%2ffRmBrNlE8mUdHovbEdChAE9JKw7OoSeKtrck%3d&amp;sp=forums">K. Renno</a> indicated to run a command to skip loading some packages:</p>
<p><strong>devenv.exe /resetskippkgs </strong></p>
<p>Or to generate a report:   <br /><strong>devenv.exe /resetskippkgs&#160; /log C:\devenv-log.txt</strong></p>
<p>After that, Visual Studio could start normally without using the /resetskippkgs setting.</p>
<p>&#160;</p>
<p>Good Luck!</p>
<p>R.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=78&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2009/08/10/source-control-error-in-vs2008-and-windows-7-x64/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>
	</item>
		<item>
		<title>How to create a complete AJAX Server Control. Part 6.</title>
		<link>http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-6/</link>
		<comments>http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-6/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 02:12:16 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-6/</guid>
		<description><![CDATA[This is the last (planned) post for the series is related to using the control inside an update panel. You can access the previous ones here: Part 1 &#8211; Basic Control implementaion Part 2 &#8211; Add items (Server side) and some client side functionality Part 3 &#8211; Client side events and JSON serialisation Part 4 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=67&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the last (planned) post for the series is related to using the control inside an update panel.</p>
<p>You can access the previous ones here:</p>
<ul>
<li><a href="http://rmencia.wordpress.com/2009/06/17/how-to-create-a-complete-ajax-server-control-part-1/">Part 1 &#8211; Basic Control implementaion</a></li>
<li><a href="http://rmencia.wordpress.com/2009/06/19/how-to-create-a-complete-ajax-server-control-part-2/">Part 2 &#8211; Add items (Server side) and some client side functionality</a></li>
<li><a href="http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-3/">Part 3 &#8211; Client side events and JSON serialisation</a></li>
<li><a href="http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-4/">Part 4 &#8211; Server events, Postbacks (IPostBackEventHandler) and Callbacks (ICallbackEventHandler)</a></li>
<li><a href="http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-5/">Part 5 &#8211; Control State</a></li>
<li><a href="http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-6/">Part 6 &#8211; Working inside the Update Panel</a></li>
</ul>
<p>When you put a control inside an UpdatePannel (with UpdateMode = “Conditional” ) what it happens is that the de AJAX Framework will call the implementation of the methods in the interface Sys.IDisposable to release the resources before destroying everything inside it using the <strong>dispose()</strong> method. And once the result is returned from the server, the control gets constructed and initialised again with the <strong>initialize()</strong> method.</p>
<p>It’s important to do that to avoid side effects and help the system with the garbage collection and avoid memory leaks.</p>
<p><strong><span style="text-decoration:underline;">ShoppingCart.js</span></strong></p>
<p><pre class="brush: jscript;">
// As the control implements Sys.IDisposable, the MS Ajax Framework requires of this method.
$ShoppingCart.prototype.initialize = function()
{
	$ShoppingCart.callBaseMethod(this, "initialize");
	this._addHandlers();
}
// As the control implements Sys.IDisposable, the MS Ajax Framework requires of this method.
// This method will be use release used resources (specially required to work with Update Panels)
$ShoppingCart.prototype.dispose = function()
{
	$ShoppingCart.callBaseMethod(this, 'dispose');
	this._clearHandlers();
}
$ShoppingCart.prototype._addHandlers = function()
{
	$addHandlers(this._cartImage, {
		dblclick: Function.createDelegate(this, this._cartDoubleClick)
	});
	$addHandlers(this._infoImage, {
		click: Function.createDelegate(this, this._infoImageClick)
	});
	$addHandlers(this._closeItemsImage, {
		click: Function.createDelegate(this, this._closeItemsImageClick)
	});
}
$ShoppingCart.prototype._clearHandlers = function()
{
	// remove event handlers to avoid memory leaks
	$clearHandlers(this._cartImage);
	$clearHandlers(this._infoImage);
	$clearHandlers(this._closeItemsImage);
}
</pre></p>
<p>Once these methods are correctly called, we can put our control inside the UpdatePanel (UpdateMode=&#8221;Conditional&#8221;). But before doing that, let’s check what’s going behind the scenes with the full postback.</p>
<p>To do that enable the Web Development Helper bar (it’s included in IE8 and you can download it for IE7).</p>
<p><a href="http://rmencia.files.wordpress.com/2009/06/image2.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" src="http://rmencia.files.wordpress.com/2009/06/image_thumb2.png?w=640&#038;h=571" border="0" alt="image" width="640" height="571" /></a></p>
<p>Then enable logging and click on the Add item button.</p>
<p><a href="http://rmencia.files.wordpress.com/2009/06/image3.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" src="http://rmencia.files.wordpress.com/2009/06/image_thumb3.png?w=601&#038;h=208" border="0" alt="image" width="601" height="208" /></a></p>
<p>Well, these are the calls to the server and the size of the downloaded elements (you can double click in each of them to see what’s what).</p>
<p>Now let’s put the control in the UpdatePanel, restart the page and enable logging one more time.</p>
<p><strong><span style="text-decoration:underline;">ShoppingCart.aspx</span></strong></p>
<p><pre class="brush: xml;">
        
            
                
            
        
</pre></p>
<p>It seems that nothing happened because only the shopping cart control was updated. Check how the amount of data received has been reduces dramatically, 3 connections instead of 7 and the page connection reduced from 10Kb to 6Kb. If we open the received data we can see how the creation of the control was sent from the server along with the html representation as I had explained before.</p>
<p>If you have any problems with JS running inside Update Panels and Postbacks, this is the tool you can use to check what was sent and returned.</p>
<p><a href="http://rmencia.files.wordpress.com/2009/06/image4.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" src="http://rmencia.files.wordpress.com/2009/06/image_thumb4.png?w=802&#038;h=340" border="0" alt="image" width="802" height="340" /></a></p>
<p>Well, I hope that you learnt few things about AJAX Server controls and the MS AJAX Framework. A good way to keep learning about it is downloading the source code for the AjaxControlToolkit and have a look at the samples and controls, believe me, there’s plenty there.</p>
<p>You can download the code <a href="http://rmencia.files.wordpress.com/2009/06/ajaxservercontrol-part1-6-zip.jpg">here</a>.<br />
<em><span style="color:#ff0000;">Important:</span> I couldn&#8217;t upload the file as it was a zip file, so I added the extension jpg. After saving the file, remove the extension and unzip it normally.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=67&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2009/06/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2009/06/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://rmencia.files.wordpress.com/2009/06/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>How to create a complete AJAX Server Control. Part 5.</title>
		<link>http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-5/</link>
		<comments>http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-5/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 00:42:49 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-5/</guid>
		<description><![CDATA[In the previous post we saw that the Items were disappeared like cowards once we executed a postback. That’s the standard behaviour of the GridView control as well, so don&#8217;t worry. To maintain the Items we have several choices: The basic implementation is to keep the list in the view state (that’s the implementation in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=58&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-4/">previous post</a> we saw that the Items were disappeared like cowards once we executed a postback. That’s the standard behaviour of the GridView control as well, so don&#8217;t worry.</p>
<p>To maintain the Items we have several choices:</p>
<ol>
<li>The basic implementation is to keep the list in the view state (that’s the implementation in the samples). This will work with no issues but it’s not very configurable</li>
<p><pre class="brush: csharp;">
		List items
		{
			get { return GetPropertyValue("items", (List)null); }
			set { SetPropertyValue("items", value); }
		}
</pre></p>
<li>A bit more sofisticated solution, and the way GridView works, would be taking into consideration the EnableViewState property and depending on the value, then saving it in the View State or in a member</li>
<p><pre class="brush: csharp;">
		List _items = new List();
		List items
		{
			get
			{
				if (EnableViewState)
					return GetPropertyValue("items", (List)null);
				else
					return _items;
			}
			set
			{
				if( value == null)
					value = new List();

				if (EnableViewState)
					SetPropertyValue("items", value);
				else
					_items = value;
			}
		}
</pre></ol>
<p>If we run the example now, we can see how all the items are there after the postback and the new ones are added to the list, just as expected. Just remember that the more you add to the ViewState, de bigger the page.</p>
<p>You can download the code <a href="http://rmencia.files.wordpress.com/2009/06/ajaxservercontrol-part1-6-zip.jpg">here</a>.<br />
<em><span style="color:#ff0000;">Important:</span> I couldn&#8217;t upload the file as it was a zip file, so I added the extension jpg. After saving the file, remove the extension and unzip it normally.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=58&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2009/06/23/how-to-create-a-complete-ajax-server-control-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>
	</item>
		<item>
		<title>How to create a complete AJAX Server Control. Part 4.</title>
		<link>http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-4/</link>
		<comments>http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-4/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 05:57:25 +0000</pubDate>
		<dc:creator>Roberto Mencia</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-4/</guid>
		<description><![CDATA[In this post I’m going to add functionality in the client side that will be executed in the server side (for previous posts of the series please refer to part 1, part 2 and part 3). To achieve this, there are 2 interfaces that have been defined: System.Web.UI.IPostBackEventHandler: used to implement postbacks System.Web.UI.ICallbackEventHandler: used to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=52&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I’m going to add functionality in the client side that will be executed in the server side (for previous posts of the series please refer to <a href="http://rmencia.wordpress.com/2009/06/17/how-to-create-a-complete-ajax-server-control-part-1/">part 1</a>, <a href="http://rmencia.wordpress.com/2009/06/19/how-to-create-a-complete-ajax-server-control-part-2/">part 2</a> and <a href="http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-3/">part 3</a>).</p>
<p>To achieve this, there are 2 interfaces that have been defined:</p>
<ul>
<li><em><strong>System.Web.UI.IPostBackEventHandler</strong></em>: used to implement postbacks</li>
<li><em><strong>System.Web.UI.ICallbackEventHandler</strong></em>: used to implement callbacks</li>
</ul>
<p>In the sample I’ll be implementing both of them; however the one that we are going to find more useful will be the one used for the postbacks, as it involves a change of state in the server control. Callbacks can be useful if we want to run something in the server and get a value as response but doesn’t require changes in the server side of control.</p>
<p>Before implementing the interfaces we need to define the events that we want to implement in the server side. To do that I have defined the ServerEvent enum with the 2 events that I want to capture in the JS and run in the server, <strong>DoubleClick</strong> and <strong>ItemAdded</strong> (I have also created 2 delegates for the events to show how to fully customise everything; <em>ClickEventHandler</em> and <em>ItemAddedEventHandler</em>). And then 2 methods to raise the events, <strong>OnDoubleClick</strong> and <strong>OnItemAdded</strong>.</p>
<p>So far, so good, but the client side needs to know which events have been hooked in the server side so that we only call the server side if it’s required. <strong>RunAtServerEvents</strong> checks which events have to be raised and sends to the client the list of events (a string with events separated by “;” and implemented as a client side property). Then we have the property <strong>AutoPostBack</strong> so we can decide if we want to execute them as postbacks or callbacks (for simplicity I’ll be assuming all as postbacks or all as callbacks but we could customise for each of them in the JS code). And finally we need the property <strong>CallbackID</strong>, required to implement the callbacks and postbacks (initialised to <strong>UniqueID</strong>).</p>
<p>Something interesting to notice is that on OnPreRender there is a piece of code that I found somewhere in the code of one of the AjaxControlToolkit controls, it seems that we need to add a call to <strong><em>Page.ClientScript.GetCallbackEventReference(this, &#8220;&#8221;, &#8220;&#8221;, &#8220;&#8221;)</em></strong> to make the callbacks work (required code to register callbacks in the client).</p>
<p><strong><span style="text-decoration:underline;">ShoppingCart.cs</span></strong></p>
<p><pre class="brush: csharp;">
	/// 
	/// Click delegate definition
	/// 
	/// 
	public delegate void ClickEventHandler(object sender);

	/// 
	/// Item added delegate
	/// 
	/// 
	/// new item
	public delegate void ItemAddedEventHandler(object sender, ShoppingCartItem addedItem);

	public class ShoppingCart : ScriptControlBase
	{

		/// 
		/// Server events raised from the client
		/// 
		enum ServerEvent
		{
			DoubleClick,
			ItemAdded
		}

		//...

		protected override void OnPreRender(EventArgs e)
		{
			if (!this.DesignMode)
			{
				if (ScriptManager.GetCurrent(Page) == null)
				{
					throw new HttpException("A ScriptManager control must exist on the current page.");
				}
				InitialiseControls();

				CreateHTMLItems();

				CallbackID = UniqueID; // needed for the callbacks and postbacks

				// Create JavaScript function for ClientCallBack WebForm_DoCallBack
				// Not sure why we need it, but the callback doesn't get registered on the client side properly without it.
				Page.ClientScript.GetCallbackEventReference(this, "", "", "");

			}

			base.OnPreRender(e);
		}

		#region Server Events
		/// 
		/// If we want to execute server events with a postback.
		/// True: A full postback happens and the page will be refreshed.
		/// Use UpdatePanel control to refresh certain areas.
		/// False: The events will run on the server with no postback (it'll use a Callback).
		/// If any data is updated a manual UI refresh needs to be forced (full page or UpdatePanel).
		/// 
		[Description("If we want to execute server events with a postback.")]
		[ExtenderControlProperty]
		public bool AutoPostBack
		{
			[DebuggerStepThrough]
			get { return GetPropertyValue("AutoPostback", true); }
			[DebuggerStepThrough]
			set { SetPropertyValue("AutoPostback", value); }
		}

		/// 
		/// Control ID to be used when doing callbacks from the client
		/// 
		[ExtenderControlProperty]
		//[ClientPropertyName("CallbackID")]
		[Browsable(false)]
		public string CallbackID
		{
			[DebuggerStepThrough]
			get { return GetPropertyValue("CallbackID", UniqueID); }
			[DebuggerStepThrough]
			set { SetPropertyValue("CallbackID", value); }
		}

		/// 
		/// Events that will be run at server
		/// 
		[Browsable(false)]
		[ExtenderControlProperty]
		[ClientPropertyName("runAtServerEvents")]
		public string RunAtServerEvents
		{
			get
			{
				string runAtServerEvents = "";

				if (DoubleClick != null) runAtServerEvents += "DoubleClick;";
				if (ItemAdded != null) runAtServerEvents += "ItemAdded;";

				if (runAtServerEvents.Length &gt; 0)
					return runAtServerEvents.Substring(0, runAtServerEvents.Length - 1);
				else
					return "";
			}
			set { }
		}

		/// 
		/// Event raised when the a cell is double clicked
		/// 
		[Description("Event raised when the a cell is double clicked.")]
		public event ClickEventHandler DoubleClick;

		/// 
		/// Raise DoubleClick event
		/// 
		/// 
		protected virtual void OnDoubleClick()
		{
			if (DoubleClick != null)
			{
				DoubleClick(this);
			}
		}

		/// 
		/// Event raised when the a cell is double clicked
		/// 
		[Description("Event raised when the a cell is double clicked.")]
		public event ItemAddedEventHandler ItemAdded;

		/// 
		/// Raise DoubleClick event
		/// 
		/// 
		protected virtual void OnItemAdded(ShoppingCartItem item)
		{
			if (ItemAdded != null)
			{
				ItemAdded(this, item);
			}
		}
		#endregion
	}
</pre></p>
<p>The next step is the implementation of the interfaces code that will be called by the AJAX framework, <strong>IPostBackEventHandler</strong> and <strong>ICallbackEventHandler</strong>. To keep it simple I’ll implement the same code in both.</p>
<p>The method that does the work is <strong>ExecuteServerEvent</strong>, in where the parameter coming from the client will define the event name and the parameters (I’ve kept it simple and I’ve used “eventname;jsonParameters”). Double click doesn’t receive any parameters, but ItemAdded receives as a parameter the new item that has been added to the shopping cart. From there, all is standard C#.</p>
<p><strong><span style="text-decoration:underline;">ShoppingCart.cs</span></strong></p>
<p><pre class="brush: csharp;">
	public class ShoppingCart : ScriptControlBase, IPostBackEventHandler, ICallbackEventHandler
	{

		//...
		#region Server Events

		//...

		/// 
		/// Executes the server event
		/// 
		/// 
		/// Event Parameters created in the client that follows this structure.
		/// EventName;JSON object serialised
		/// i.e:
		///		ItemAdded;JSON serialised
		/// 
		/// 
		private string ExecuteServerEvent(string eventFromClient)
		{
			// Get the event name
			int separator = eventFromClient.IndexOf(";");
			string serverEvent = eventFromClient.Substring(0, separator);
			ServerEvent e = (ServerEvent)Enum.Parse(typeof(ServerEvent), serverEvent);

			// Get the event args (JSON serialised string)
			string eventArgs = eventFromClient.Substring(separator + 1);

			switch (e)
			{
				case ServerEvent.DoubleClick:
					OnDoubleClick();
					break;
				case ServerEvent.ItemAdded:
					ShoppingCartItem addedItem = new JavaScriptSerializer().Deserialize(eventArgs);
					AddItem(addedItem);
					break;
				default:
					throw new Exception("Wrong event!");
					break;
			}
			return "";
		}

		/// 
		/// Adds an item
		/// 
		/// 
		private void AddItem(ShoppingCartItem addedItem)
		{
			Items.Add(addedItem);

			OnItemAdded(addedItem);
		}
		#endregion 

		#region IPostBackEventHandler Members

		/// 
		/// Raise postback event in the server.
		/// 
		/// argument from JScript
		public void RaisePostBackEvent(string eventArgument)
		{
			ExecuteServerEvent(eventArgument);
		}
		#endregion

		#region ICallbackEventHandler Members
		/// 
		/// Return value for the callback call
		/// 
		string callbackResult = "";

		/// 
		/// Returns the value generated by the event (if any).
		/// 
		/// 
		string ICallbackEventHandler.GetCallbackResult()
		{
			return callbackResult;
		}

		/// 
		/// Raises the server event in the server.
		/// 
		/// argument from JScript
		void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
		{
			callbackResult = ExecuteServerEvent(eventArgument);
		}
		#endregion
	}
</pre></p>
<p>In the client side we need to add some code to raise the events (and implement JS properties). The method that will call the server is _raiseServerEvent.</p>
<ol>
<li>It checks the the event that we want to fire has been hooked up in the server side</li>
<li>It creates the parameters with the event name to call and the parameters required for that event</li>
<li>Depending if we want to execute a postback or a callback it calls the server in a different way.</li>
<li>As Callbacks run asynchronously, we need to provide the methods to execute in case it was successful and if there was an error.</li>
</ol>
<p><strong><span style="text-decoration:underline;">ShoppingCart.js</span></strong></p>
<p><pre class="brush: jscript;">
// -------------------------------------- Client side Properties --------------------------------------
$ShoppingCart.prototype.get_items = function() { return this._items; }
$ShoppingCart.prototype.set_items = function(value)
{
	this._items = Sys.Serialization.JavaScriptSerializer.deserialize(value);
}

$ShoppingCart.prototype.get_CallbackID = function() { return this._CallbackID; }
$ShoppingCart.prototype.set_CallbackID = function(value) { this._CallbackID = value; }

$ShoppingCart.prototype.get_AutoPostBack = function() { return this._AutoPostBack; }
$ShoppingCart.prototype.set_AutoPostBack = function(value) { this._AutoPostBack = value; }

// -------------------------------------- Server Side Events --------------------------------------
$ShoppingCart.prototype.get_runAtServerEvents = function()
{
	return this._runAtServerEvents;
}

$ShoppingCart.prototype.set_runAtServerEvents = function(value)
{
	this._runAtServerEvents = value.split(';');
}

$ShoppingCart.prototype._raiseServerEvent = function(eventName, eventArgs)
{
	if (!Array.contains(this._runAtServerEvents, eventName))	return;

	var eventArgsSerialised = Sys.Serialization.JavaScriptSerializer.serialize(eventArgs);
	var args = String.format("{0};{1}", eventName, eventArgsSerialised);
	var id = this._CallbackID;

	if (this._AutoPostBack)
	{// calls IPostBackEventHandler.RaisePostBackEvent in the server control
		__doPostBack(id, args);
	}
	else
	{
		// calls ICallbackEventHandler.RaiseCallbackEvent
		// the return value from ICallbackEventHandler.GetCallbackResult() is sent
		// to the callback handler this._receiveServerData
		WebForm_DoCallback(id, args, this._receiveServerData, this, this._onCallbackError, true)
	}
}

// Handler for successful return from callback
$ShoppingCart.prototype._receiveServerData = function(arg, context)
{
	// context is the instance of the class (this)

	// update the UI or Raise an event to inform that we finished the callback
	alert("Back from the callback!");
	//context.updateUI();
	//context.raiseEndClientCallback(arg);
}

// Error handler for the callback
$ShoppingCart.prototype._onCallbackError = function(message, context)
{
	alert(String.format(AjaxControlToolkit.Resources.Rating_CallbackError, message));
}

// -------------------------------------- Control methods --------------------------------------
$ShoppingCart.prototype.addItem = function(itemText, itemDescription, itemQuantity, itemTotalPrice)
{
	var newItem = new $ShoppingCartItem(itemText, itemDescription, itemQuantity, itemTotalPrice);

	this._raiseServerEvent("ItemAdded", newItem);
}

// Classes to handle event arguments and data transfer to the server ---------------------------------
var $ShoppingCartItem = AjaxControl.ShoppingCartItem = function(itemText, itemDescription, itemQuantity, itemTotalPrice)
{
	this.Text = itemText;
	this.Description = itemDescription;
	this.Quantity = itemQuantity;
	this.TotalPrice = itemTotalPrice;
}
</pre></p>
<p>To test it, let’s add some code to our web page. I have added 4 text boxes to introduce the values and and a button that will add the new item. Additionally I added a GridView control that is Databinded with the items in the shopping cart (server event of ItemAdded).</p>
<p><strong><span style="text-decoration:underline;">ShoppingCart.aspx</span></strong></p>
<p><pre class="brush: xml;">

    

        function addNewItem() 
        {
            $find(&quot;Cart1&quot;).addItem(
                    $get(&quot;newItemText&quot;).value,
                    $get(&quot;newItemDescription&quot;).value,
                    $get(&quot;newItemQuantity&quot;).value,
                    $get(&quot;newItemTotalPrice&quot;).value
                    );
        
        }
    



    
    
    
    &lt;div&gt;
        &lt;table&gt;
            &lt;tr&gt;
                &lt;td&gt;Text&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;Description&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;Quantity&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;TotalPrice&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot; align=&quot;right&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
         &lt;/table&gt;
    &lt;/div&gt;
    &lt;div&gt;
        

        
    &lt;/div&gt;
    

</pre></p>
<p><strong><span style="text-decoration:underline;">ShoppingCart.aspx.cs</span></strong></p>
<p><pre class="brush: csharp;">
	public partial class ShoppingCart : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if(! IsPostBack)
			{
				var items = new List
				{
					//...
				};

				Cart1.Items = items;

				GridView1.DataSource = Cart1.Items;
				GridView1.DataBind();
			}
		}

		protected void Cart1_ItemAdded(object sender, ShoppingCartItem addedItem)
		{
			GridView1.DataSource = Cart1.Items;
			GridView1.DataBind();
		}
	}
</pre></p>
<p>As you will notice the old items are lost after the postback and only the latest item is rendered. This is the expected behaviour (Gridview implementation behaves the same). Next post I’ll show how to make the control remember the previous items.</p>
<p>Well, that’s all. I know that there’s a lot to digest here but believe me, if you had to figure it out by yourself it would take a lot longer.</p>
<p>You can download the code <a href="http://rmencia.files.wordpress.com/2009/06/ajaxservercontrol-part1-6-zip.jpg">here</a>.<br />
<em><span style="color:#ff0000;">Important:</span> I couldn&#8217;t upload the file as it was a zip file, so I added the extension jpg. After saving the file, remove the extension and unzip it normally.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rmencia.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rmencia.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rmencia.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rmencia.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rmencia.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rmencia.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rmencia.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rmencia.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rmencia.wordpress.com&amp;blog=3981830&amp;post=52&amp;subd=rmencia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rmencia.wordpress.com/2009/06/22/how-to-create-a-complete-ajax-server-control-part-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/947a48289c95630d756cbe3cecfa3aa6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">rmencia</media:title>
		</media:content>
	</item>
	</channel>
</rss>
