<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Damir's Corner</title>
    <link>http://www.damirscorner.com/</link>
    <description>Notes from Daily Encounters with Technology</description>
    <language>en-us</language>
    <copyright>Damir Arh, M. Sc.</copyright>
    <lastBuildDate>Sun, 09 Aug 2009 17:39:38 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>damir.arh@gmail.com</managingEditor>
    <webMaster>damir.arh@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=21209566-9f7f-4939-ace5-d224080bb8b1</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=21209566-9f7f-4939-ace5-d224080bb8b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft Exchange supports Send As and Send On Behalf Of permissions to be granted
to users for individual e-mail addresses. Sending e-mail from Outlook for these users
is very simple – they just enter the desired address in the From field of a new message
(toggled with the Show From command on the Options ribbon) and if they have the required
permission it will be sent accordingly – either as if it was actually sent from that
address or as sent by the user on behalf of the address in the From field.
</p>
        <p>
If you want to achieve this from code there is a little more work involved. First
of all the user must be authenticated on the server using one of the methods below:
</p>
        <p>
          <font face="Courier New">SmtpClient smtp = new SmtpClient("smtp.domain.com");</font>
        </p>
        <p>
          <font face="Courier New">// use user’s existing credentials<br />
smtp.UseDefaultCredentials = true;</font>
        </p>
        <p>
          <font face="Courier New">// pass username and password<br />
smtp.Credentials = new NetworkCredentials("username", "password");</font>
        </p>
        <p>
The next step is to set up the correct headers in the message otherwise the server
will return error code 5.7.1 describing the permission the user does not have.
</p>
        <p>
To send the e-mail as only the From property has to contain the desired address:
</p>
        <p>
          <font face="Courier New">MailMessage mail = new MailMessage();<br />
mail.From = new MailAddress("send.as@domain.com");</font>
        </p>
        <p>
To send the e-mail on behalf of another user the Sender property must additionally
contain the user’s e-mail address:
</p>
        <p>
          <font face="Courier New">MailMessage mail = new MailMessage();<br />
mail.From = new MailAddress("send.as@domain.com");<br />
mail.Sender = new MailAddress("user.address@domain.com");</font>
        </p>
        <p>
On a related note, the required permissions can be granted using PowerShell.
</p>
        <p>
To grant the Send As permission:
</p>
        <p>
          <font face="Courier New">Add-ADPermission –Identity "user1" –User "user2" –ExtendedRights
Send-As</font>
        </p>
        <p>
To grant the Send On Behalf Of permission:
</p>
        <p>
          <font face="Courier New">Set-Mailbox "user1" -GrantSendOnBehalfTo "user2"</font>
        </p>
        <p>
In both cases the user1 specifies the mailbox to grant the permission for and the
user2 specifies the user to grant the permission to.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=21209566-9f7f-4939-ace5-d224080bb8b1" />
      </body>
      <title>Send E-Mail As and On Behalf Of</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</guid>
      <link>http://www.damirscorner.com/SendEMailAsAndOnBehalfOf.aspx</link>
      <pubDate>Sun, 09 Aug 2009 17:39:38 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft Exchange supports Send As and Send On Behalf Of permissions to be granted
to users for individual e-mail addresses. Sending e-mail from Outlook for these users
is very simple – they just enter the desired address in the From field of a new message
(toggled with the Show From command on the Options ribbon) and if they have the required
permission it will be sent accordingly – either as if it was actually sent from that
address or as sent by the user on behalf of the address in the From field.
&lt;/p&gt;
&lt;p&gt;
If you want to achieve this from code there is a little more work involved. First
of all the user must be authenticated on the server using one of the methods below:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;SmtpClient smtp = new SmtpClient("smtp.domain.com");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;// use user’s existing credentials&lt;br&gt;
smtp.UseDefaultCredentials = true;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;// pass username and password&lt;br&gt;
smtp.Credentials = new NetworkCredentials("username", "password");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The next step is to set up the correct headers in the message otherwise the server
will return error code 5.7.1 describing the permission the user does not have.
&lt;/p&gt;
&lt;p&gt;
To send the e-mail as only the From property has to contain the desired address:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;MailMessage mail = new MailMessage();&lt;br&gt;
mail.From = new MailAddress("send.as@domain.com");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
To send the e-mail on behalf of another user the Sender property must additionally
contain the user’s e-mail address:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;MailMessage mail = new MailMessage();&lt;br&gt;
mail.From = new MailAddress("send.as@domain.com");&lt;br&gt;
mail.Sender = new MailAddress("user.address@domain.com");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
On a related note, the required permissions can be granted using PowerShell.
&lt;/p&gt;
&lt;p&gt;
To grant the Send As permission:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Add-ADPermission –Identity "user1" –User "user2" –ExtendedRights
Send-As&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
To grant the Send On Behalf Of permission:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Set-Mailbox "user1" -GrantSendOnBehalfTo "user2"&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
In both cases the user1 specifies the mailbox to grant the permission for and the
user2 specifies the user to grant the permission to.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=21209566-9f7f-4939-ace5-d224080bb8b1" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=0db675f9-82f2-4907-933d-9dccc5f07115</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,0db675f9-82f2-4907-933d-9dccc5f07115.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,0db675f9-82f2-4907-933d-9dccc5f07115.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0db675f9-82f2-4907-933d-9dccc5f07115</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I decided to get to the bottom of the missing driver issue on my computer running
Windows 7 RC. It shows up as PCI Simple Communications controller and it really bugged
me since I don't have a modem or a similar device on the motherboard.
</p>
        <p>
          <img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="PCI Simple Communications Controller" alt="PCI Simple Communications Controller" src="http://www.damirscorner.com/content/binary/IdentifyingunrecognizeddevicesinDeviceMa_F2FE/PCISimpleCommunicationsController.png" border="0" height="36" width="268" />It
turned out that there is a away to identify such a device from the information available
in Device Manager. The first step is to open the Properties window for this device
and move to the Details tab. After selecting the Hardware Ids in the Property dropdown
the device identifiers are displayed.
</p>
        <p>
          <img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="HardwareIds" alt="HardwareIds" src="http://www.damirscorner.com/content/binary/IdentifyingunrecognizeddevicesinDeviceMa_F2FE/HardwareIds.png" border="0" height="461" width="414" />
        </p>
        <p>
The important ones are the numbers written after the VEN and DEV keywords. The first
one is the Vendor ID and the second one is the Device ID. So in my case the Vendor
ID is 8086 (from VEN_8086) and the Device ID is 29A4 (from DEV_29A4).
</p>
        <p>
All that's left to do know is to go to <a href="http://www.pcidatabase.com" target="_blank">PCIDatabase.com</a> and
enter the ids into the corresponding search boxes. In my case it turned out that it
was a device from Intel - Intel Management Engine Interface (HECI). Unfortunately
it doesn't have <a href="http://downloadcenter.intel.com/filter_results.aspx?strTypes=all&amp;ProductID=2374&amp;OSFullName=Windows+7%2C+64-bit*&amp;lang=eng&amp;strOSs=190&amp;submit=Go%21" target="_blank">a
driver for Windows 7</a> yet and <a href="http://downloadcenter.intel.com/filter_results.aspx?strTypes=all&amp;ProductID=2374&amp;OSFullName=Windows+Vista+64*&amp;lang=eng&amp;strOSs=150&amp;submit=Go%21" target="_blank">the
Vista one</a> doesn't install. But hey, at least I know which driver is missing.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=0db675f9-82f2-4907-933d-9dccc5f07115" />
      </body>
      <title>Identifying unrecognized devices in Device Manager</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,0db675f9-82f2-4907-933d-9dccc5f07115.aspx</guid>
      <link>http://www.damirscorner.com/IdentifyingUnrecognizedDevicesInDeviceManager.aspx</link>
      <pubDate>Sat, 01 Aug 2009 17:09:49 GMT</pubDate>
      <description>&lt;p&gt;
Today I decided to get to the bottom of the missing driver issue on my computer running
Windows 7 RC. It shows up as PCI Simple Communications controller and it really bugged
me since I don't have a modem or a similar device on the motherboard.
&lt;/p&gt;
&lt;p&gt;
&lt;img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="PCI Simple Communications Controller" alt="PCI Simple Communications Controller" src="http://www.damirscorner.com/content/binary/IdentifyingunrecognizeddevicesinDeviceMa_F2FE/PCISimpleCommunicationsController.png" border="0" height="36" width="268"&gt;It
turned out that there is a away to identify such a device from the information available
in Device Manager. The first step is to open the Properties window for this device
and move to the Details tab. After selecting the Hardware Ids in the Property dropdown
the device identifiers are displayed.
&lt;/p&gt;
&lt;p&gt;
&lt;img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="HardwareIds" alt="HardwareIds" src="http://www.damirscorner.com/content/binary/IdentifyingunrecognizeddevicesinDeviceMa_F2FE/HardwareIds.png" border="0" height="461" width="414"&gt; 
&lt;/p&gt;
&lt;p&gt;
The important ones are the numbers written after the VEN and DEV keywords. The first
one is the Vendor ID and the second one is the Device ID. So in my case the Vendor
ID is 8086 (from VEN_8086) and the Device ID is 29A4 (from DEV_29A4).
&lt;/p&gt;
&lt;p&gt;
All that's left to do know is to go to &lt;a href="http://www.pcidatabase.com" target="_blank"&gt;PCIDatabase.com&lt;/a&gt; and
enter the ids into the corresponding search boxes. In my case it turned out that it
was a device from Intel - Intel Management Engine Interface (HECI). Unfortunately
it doesn't have &lt;a href="http://downloadcenter.intel.com/filter_results.aspx?strTypes=all&amp;amp;ProductID=2374&amp;amp;OSFullName=Windows+7%2C+64-bit*&amp;amp;lang=eng&amp;amp;strOSs=190&amp;amp;submit=Go%21" target="_blank"&gt;a
driver for Windows 7&lt;/a&gt; yet and &lt;a href="http://downloadcenter.intel.com/filter_results.aspx?strTypes=all&amp;amp;ProductID=2374&amp;amp;OSFullName=Windows+Vista+64*&amp;amp;lang=eng&amp;amp;strOSs=150&amp;amp;submit=Go%21" target="_blank"&gt;the
Vista one&lt;/a&gt; doesn't install. But hey, at least I know which driver is missing.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=0db675f9-82f2-4907-933d-9dccc5f07115" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,0db675f9-82f2-4907-933d-9dccc5f07115.aspx</comments>
      <category>Personal</category>
      <category>Personal/Software</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=4e0955bd-674c-4a1f-b657-91a361e2c0eb</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,4e0955bd-674c-4a1f-b657-91a361e2c0eb.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,4e0955bd-674c-4a1f-b657-91a361e2c0eb.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4e0955bd-674c-4a1f-b657-91a361e2c0eb</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://gama-system.com/Content.aspx?id=20050200">Gama System eArchive</a>,
one of the two products in our <a href="http://gama-system.com/Content.aspx?id=20050050">document
product line</a>, received accreditation from the <a href="http://www.arhiv.gov.si/en/">Archives
of the Republic of Slovenia</a> last week. This acknowledgement by our national body
means that any document stored in Gama System eArchive is automatically legally valid.
</p>
        <p>
This is important for both <a href="http://gama-system.com/NewsItems.aspx">our company</a> and
other companies looking for a long term electronic document storage solution. Our
product is the first service oriented solution to receive the accreditation.
</p>
        <p>
Congratulations to everyone involved in the product. Well done!
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=4e0955bd-674c-4a1f-b657-91a361e2c0eb" />
      </body>
      <title>Gama System eArchive accredited</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,4e0955bd-674c-4a1f-b657-91a361e2c0eb.aspx</guid>
      <link>http://www.damirscorner.com/GamaSystemEArchiveAccredited.aspx</link>
      <pubDate>Sat, 05 Jul 2008 20:37:14 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://gama-system.com/Content.aspx?id=20050200"&gt;Gama System eArchive&lt;/a&gt;,
one of the two products in our &lt;a href="http://gama-system.com/Content.aspx?id=20050050"&gt;document
product line&lt;/a&gt;, received accreditation from the &lt;a href="http://www.arhiv.gov.si/en/"&gt;Archives
of the Republic of Slovenia&lt;/a&gt; last week. This acknowledgement by our national body
means that any document stored in Gama System eArchive is automatically legally valid.
&lt;/p&gt;
&lt;p&gt;
This is important for both &lt;a href="http://gama-system.com/NewsItems.aspx"&gt;our company&lt;/a&gt; and
other companies looking for a long term electronic document storage solution. Our
product is the first service oriented solution to receive the accreditation.
&lt;/p&gt;
&lt;p&gt;
Congratulations to everyone involved in the product. Well done!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=4e0955bd-674c-4a1f-b657-91a361e2c0eb" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,4e0955bd-674c-4a1f-b657-91a361e2c0eb.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Personal</category>
      <category>Personal/Software</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=de988151-8abf-4eef-bdc2-1126b05812b1</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,de988151-8abf-4eef-bdc2-1126b05812b1.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,de988151-8abf-4eef-bdc2-1126b05812b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=de988151-8abf-4eef-bdc2-1126b05812b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I've taken my new <a href="http://buy.garmin.com/shop/shop.do?pID=8703">handeld
GPS device</a> for a test run. It did its job pretty well but the real challenge started
afterwards when I tried geotagging the photos I've taken. I decided to use <a href="http://www.microsoft.com/prophoto/downloads/tools.aspx">Microsoft
Pro Photo Tools</a> which have just been released with geotagging as its main feature.
Downloading the track data from the GPS device with Garmin MapSource software was
quick and simple. But the problems started soon afterwards. MapSource can only export
track data in its proprietary format GDB which can't be used in Microsoft Pro Photo
Tools.
</p>
        <p>
          <a href="http://www.gpsbabel.org/">GPSBabel</a> came to the rescue. This free tool
can probably convert files between any two existing GPS formats, at least judging
from its <a href="http://www.gpsbabel.org/capabilities.html">list of supported formats</a>.
I used it to convert my data to the GPX XML format only to find out that Microsoft
Pro Photo Tools have problems with it. Converting to NMEA or KML instead didn't help
either. Fortunately the latter returned a strange error (Degrees must be between 0
and 90, found degree 46298501) which put me on the right track. Of course there was
no such value in the KML file so I correctly deduced that the decimal separator was
to blame.
</p>
        <p>
The value in the file was 46.298501 but the Slovenian regional settings have comma
as the decimal separator therefore the value was misinterpreted. Temporarily changing
the decimal separator to dot solved the problem - the track was successfully imported
immediately afterwards. This issue won't keep me from using this otherwise very useful
tool with a really nice feature set. It could even fix the mismatching time settings
between my GPS unit and the camera with a single setting. I just hope they address
this bug soon so that I won't have to change my regional settings every time I use
the program.
</p>
        <p>
The only thing I still have to figure out is why the geotags somehow lost resolution
when I uploaded the photos from <a href="http://picasa.google.com/">Picasa</a> to <a href="http://picasaweb.google.com/">Picasa
Web Albums</a>. I just fixed them manually and decided to address the issue next time.
Any tips are welcome.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=de988151-8abf-4eef-bdc2-1126b05812b1" />
      </body>
      <title>Microsoft Pro Photo Tools decimal separator problem</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,de988151-8abf-4eef-bdc2-1126b05812b1.aspx</guid>
      <link>http://www.damirscorner.com/MicrosoftProPhotoToolsDecimalSeparatorProblem.aspx</link>
      <pubDate>Sun, 15 Jun 2008 20:03:01 GMT</pubDate>
      <description>&lt;p&gt;
Today I've taken my new &lt;a href="http://buy.garmin.com/shop/shop.do?pID=8703"&gt;handeld
GPS device&lt;/a&gt; for a test run. It did its job pretty well but the real challenge started
afterwards when I tried geotagging the photos I've taken. I decided to use &lt;a href="http://www.microsoft.com/prophoto/downloads/tools.aspx"&gt;Microsoft
Pro Photo Tools&lt;/a&gt; which have just been released with geotagging as its main feature.
Downloading the track data from the GPS device with Garmin MapSource software was
quick and simple. But the problems started soon afterwards. MapSource can only export
track data in its proprietary format GDB which can't be used in Microsoft Pro Photo
Tools.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.gpsbabel.org/"&gt;GPSBabel&lt;/a&gt; came to the rescue. This free tool
can probably convert files between any two existing GPS formats, at least judging
from its &lt;a href="http://www.gpsbabel.org/capabilities.html"&gt;list of supported formats&lt;/a&gt;.
I used it to convert my data to the GPX XML format only to find out that Microsoft
Pro Photo Tools have problems with it. Converting to NMEA or KML instead didn't help
either. Fortunately the latter returned a strange error (Degrees must be between 0
and 90, found degree 46298501) which put me on the right track. Of course there was
no such value in the KML file so I correctly deduced that the decimal separator was
to blame.
&lt;/p&gt;
&lt;p&gt;
The value in the file was 46.298501 but the Slovenian regional settings have comma
as the decimal separator therefore the value was misinterpreted. Temporarily changing
the decimal separator to dot solved the problem - the track was successfully imported
immediately afterwards. This issue won't keep me from using this otherwise very useful
tool with a really nice feature set. It could even fix the mismatching time settings
between my GPS unit and the camera with a single setting. I just hope they address
this bug soon so that I won't have to change my regional settings every time I use
the program.
&lt;/p&gt;
&lt;p&gt;
The only thing I still have to figure out is why the geotags somehow lost resolution
when I uploaded the photos from &lt;a href="http://picasa.google.com/"&gt;Picasa&lt;/a&gt; to &lt;a href="http://picasaweb.google.com/"&gt;Picasa
Web Albums&lt;/a&gt;. I just fixed them manually and decided to address the issue next time.
Any tips are welcome.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=de988151-8abf-4eef-bdc2-1126b05812b1" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,de988151-8abf-4eef-bdc2-1126b05812b1.aspx</comments>
      <category>Personal</category>
      <category>Personal/Software</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=84c751f7-f67e-47f0-9def-3035b5333cf5</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,84c751f7-f67e-47f0-9def-3035b5333cf5.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,84c751f7-f67e-47f0-9def-3035b5333cf5.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=84c751f7-f67e-47f0-9def-3035b5333cf5</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A .NET application in the company I work for recently started crashing under Windows
Vista when trying to open a window implemented in an ActiveX DLL. Investigations showed
that they were caused by an <font face="Courier New">AccessViolationException "Attempted
to read or write protected memory. This is often an indication that other memory is
corrupt."</font>. The cause was one of the ActiveX controls in the window. When instantited
directly in a .NET Form the exception above was contained in a <font face="Courier New">TargetInvocationException
"Unable to get the window handle for the '&lt;control name&gt;' control. Windowless
ActiveX controls are not supported."</font>. Knowing that the control didn't suddenly
turn windowless we dug deeper.
</p>
        <p>
It turned out that the problem appeared with .NET Framework 2.0 Service Pack 1. <a href="http://blogs.msdn.com/ed_maurer/archive/2007/12/14/nxcompat-and-the-c-compiler.aspx">Apparently</a> it
caused the C# compiler in Visual Studio 2005 and later to set the <font face="Courier New">NXCOMPAT</font> bit
for all build targets without an option to turn this new behavior off. For those who
don't know, this means that DEP (data execution prevention) will kick in unless it
is turned off completely in the operating system. This wouldn't be a big deal unless
ATL before Visual Studio 2005 didn't have a <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=299397">bug</a> which
caused the heap allocated memory not to be flagged as executable, which under the
new circumstances results as the already mentioned exception. Windows XP has DEP turned
off by default therefore everything still works but in Windows Vista it is turned
on and prevents such application from functioning properly.
</p>
        <p>
The best solution would of course be to recompile the ActiveX controls in Visual Studio
2005 or later but this might not be possible if they are supplied by a third party.
In this case the most obvious approach to dealing with the situation is to disable
DEP in Vista. There is a <font face="Courier New">Data Execution Prevention</font> tab
in the <font face="Courier New">Performance Options</font> which open when you click
the <font face="Courier New">Settings</font> button in the <font face="Courier New">Performance</font> frame
of the <font face="Courier New">Advanced</font> tab in the <font face="Courier New">System
Properties</font> dialog but it only allows switching between DEP for all processes
with defined exceptions and DEP for essential Windows programs and services, i.e.
executables flagged with the <font face="Courier New">NXCOMPAT</font> bit. The only
way to turn DEP completely off is executing the following command with administrative
privileges:
</p>
        <p>
          <font face="Courier New">bcdedit.exe /set {current} nx AlwaysOff</font>
        </p>
        <p>
After restart DEP will be turned off and problematic binaries will work once again.
To restore the previous (default) state replace <font face="Courier New">AlwaysOff</font> with <font face="Courier New">OptIn</font>.
The <font face="Courier New">AlwaysOn</font> option enables DEP for all processes
and might cause additional problems (e.g. Google Calendar Sync in its current version
0.9.3.2 doesn't work in this mode).
</p>
        <p>
Unfortunately, this solution would require all your Vista using customers to disable
DEP as well which really isn't an option for commercial software. Fortunately, there
is another solution. Although there is no compiler option to turn keep the <font face="Courier New">NXCOMPAT</font> bit
unset, you can still do this after compilation using the <font face="Courier New">editbin.exe</font> which
comes with C++ compiler for Visual Studio 2005 and later:
</p>
        <p>
          <font face="Courier New">editbin.exe /NXCOMPAT:NO &lt;filename.exe&gt;</font>
        </p>
        <p>
This command removes the <font face="Courier New">NXCOMPAT</font> bit and restores
the behavior before .NET 2.0 SP1. If your assembly was signed it also invalidates
the signature so you'll have to resign it:
</p>
        <p>
          <font face="Courier New">sn.exe -R &lt;filename.exe&gt; &lt;keyfile.snk&gt;</font>
        </p>
        <p>
You can automate this by putting the two commands in the <font face="Courier New">Post-build
event command line</font> for the project:
</p>
        <p>
          <font face="Courier New">editbin.exe /NXCOMPAT:NO "$(TargetPath)"<br />
sn.exe -R "$(TargetPath)" "$(ProjectDir)&lt;keyfile.snk&gt;"</font>
        </p>
        <p>
You might need to call <font face="Courier New">vcvars32.bat</font> before that to
put the required executables in path and enable <font face="Courier New">editbin.exe</font> dependencies
to be resolved. Note that in a completely automated build scenario using <font face="Courier New">MSBuild</font> you'll
have to specify full path for the <font face="Courier New">vcvars32.bat</font> because <font face="Courier New">$(DevEnvDir)</font> resolves
to <font face="Courier New">*Undefined*</font> outside Visual Studio 2005. Also your
strong name key should be in a <font face="Courier New">snk</font> file instead of
a password protected <font face="Courier New">pfx</font> file because <font face="Courier New">sn.exe</font><a href="http://blogs.msdn.com/shawnfa/archive/2006/02/14/531921.aspx">doesn't
allow</a> the password to be read from a redirected standard input.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=84c751f7-f67e-47f0-9def-3035b5333cf5" />
      </body>
      <title>Old ActiveX controls under .NET 2.0 SP1</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,84c751f7-f67e-47f0-9def-3035b5333cf5.aspx</guid>
      <link>http://www.damirscorner.com/OldActiveXControlsUnderNET20SP1.aspx</link>
      <pubDate>Tue, 29 Apr 2008 13:29:08 GMT</pubDate>
      <description>&lt;p&gt;
A .NET application in the company I work for recently started crashing under Windows
Vista when trying to open a window implemented in an ActiveX DLL. Investigations showed
that they were caused by an &lt;font face="Courier New"&gt;AccessViolationException "Attempted
to read or write protected memory. This is often an indication that other memory is
corrupt."&lt;/font&gt;. The cause was one of the ActiveX controls in the window. When instantited
directly in a .NET Form the exception above was contained in a &lt;font face="Courier New"&gt;TargetInvocationException
"Unable to get the window handle for the '&amp;lt;control name&amp;gt;' control. Windowless
ActiveX controls are not supported."&lt;/font&gt;. Knowing that the control didn't suddenly
turn windowless we dug deeper.
&lt;/p&gt;
&lt;p&gt;
It turned out that the problem appeared with .NET Framework 2.0 Service Pack 1. &lt;a href="http://blogs.msdn.com/ed_maurer/archive/2007/12/14/nxcompat-and-the-c-compiler.aspx"&gt;Apparently&lt;/a&gt; it
caused the C# compiler in Visual Studio 2005 and later to set the &lt;font face="Courier New"&gt;NXCOMPAT&lt;/font&gt; bit
for all build targets without an option to turn this new behavior off. For those who
don't know, this means that DEP (data execution prevention) will kick in unless it
is turned off completely in the operating system. This wouldn't be a big deal unless
ATL before Visual Studio 2005 didn't have a &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=299397"&gt;bug&lt;/a&gt; which
caused the heap allocated memory not to be flagged as executable, which under the
new circumstances results as the already mentioned exception. Windows XP has DEP turned
off by default therefore everything still works but in Windows Vista it is turned
on and prevents such application from functioning properly.
&lt;/p&gt;
&lt;p&gt;
The best solution would of course be to recompile the ActiveX controls in Visual Studio
2005 or later but this might not be possible if they are supplied by a third party.
In this case the most obvious approach to dealing with the situation is to disable
DEP in Vista. There is a &lt;font face="Courier New"&gt;Data Execution Prevention&lt;/font&gt; tab
in the &lt;font face="Courier New"&gt;Performance Options&lt;/font&gt; which open when you click
the &lt;font face="Courier New"&gt;Settings&lt;/font&gt; button in the &lt;font face="Courier New"&gt;Performance&lt;/font&gt; frame
of the &lt;font face="Courier New"&gt;Advanced&lt;/font&gt; tab in the &lt;font face="Courier New"&gt;System
Properties&lt;/font&gt; dialog but it only allows switching between DEP for all processes
with defined exceptions and DEP for essential Windows programs and services, i.e.
executables flagged with the &lt;font face="Courier New"&gt;NXCOMPAT&lt;/font&gt; bit. The only
way to turn DEP completely off is executing the following command with administrative
privileges:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;bcdedit.exe /set {current} nx AlwaysOff&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
After restart DEP will be turned off and problematic binaries will work once again.
To restore the previous (default) state replace &lt;font face="Courier New"&gt;AlwaysOff&lt;/font&gt; with &lt;font face="Courier New"&gt;OptIn&lt;/font&gt;.
The &lt;font face="Courier New"&gt;AlwaysOn&lt;/font&gt; option enables DEP for all processes
and might cause additional problems (e.g. Google Calendar Sync in its current version
0.9.3.2 doesn't work in this mode).
&lt;/p&gt;
&lt;p&gt;
Unfortunately, this solution would require all your Vista using customers to disable
DEP as well which really isn't an option for commercial software. Fortunately, there
is another solution. Although there is no compiler option to turn keep the &lt;font face="Courier New"&gt;NXCOMPAT&lt;/font&gt; bit
unset, you can still do this after compilation using the &lt;font face="Courier New"&gt;editbin.exe&lt;/font&gt; which
comes with C++ compiler for Visual Studio 2005 and later:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;editbin.exe /NXCOMPAT:NO &amp;lt;filename.exe&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
This command removes the &lt;font face="Courier New"&gt;NXCOMPAT&lt;/font&gt; bit and restores
the behavior before .NET 2.0 SP1. If your assembly was signed it also invalidates
the signature so you'll have to resign it:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;sn.exe -R &amp;lt;filename.exe&amp;gt; &amp;lt;keyfile.snk&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
You can automate this by putting the two commands in the &lt;font face="Courier New"&gt;Post-build
event command line&lt;/font&gt; for the project:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;editbin.exe /NXCOMPAT:NO "$(TargetPath)"&lt;br&gt;
sn.exe -R "$(TargetPath)" "$(ProjectDir)&amp;lt;keyfile.snk&amp;gt;"&lt;/font&gt; 
&lt;p&gt;
You might need to call &lt;font face="Courier New"&gt;vcvars32.bat&lt;/font&gt; before that to
put the required executables in path and enable &lt;font face="Courier New"&gt;editbin.exe&lt;/font&gt; dependencies
to be resolved. Note that in a completely automated build scenario using &lt;font face="Courier New"&gt;MSBuild&lt;/font&gt; you'll
have to specify full path for the &lt;font face="Courier New"&gt;vcvars32.bat&lt;/font&gt; because &lt;font face="Courier New"&gt;$(DevEnvDir)&lt;/font&gt; resolves
to &lt;font face="Courier New"&gt;*Undefined*&lt;/font&gt; outside Visual Studio 2005. Also your
strong name key should be in a &lt;font face="Courier New"&gt;snk&lt;/font&gt; file instead of
a password protected &lt;font face="Courier New"&gt;pfx&lt;/font&gt; file because &lt;font face="Courier New"&gt;sn.exe&lt;/font&gt; &lt;a href="http://blogs.msdn.com/shawnfa/archive/2006/02/14/531921.aspx"&gt;doesn't
allow&lt;/a&gt; the password to be read from a redirected standard input.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=84c751f7-f67e-47f0-9def-3035b5333cf5" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,84c751f7-f67e-47f0-9def-3035b5333cf5.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/Vista</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=ec1b3869-796e-4d12-8d41-614bcb51aad5</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,ec1b3869-796e-4d12-8d41-614bcb51aad5.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,ec1b3869-796e-4d12-8d41-614bcb51aad5.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ec1b3869-796e-4d12-8d41-614bcb51aad5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The <font face="Courier New">MonthCalendar</font> control's <font face="Courier New">BoldedDates</font> functionality
doesn't appear to work properly on Windows Vista. The dates added to any of the <font face="Courier New">BoldedDates</font>, <font face="Courier New">MonthlyBoldedDates</font> and <font face="Courier New">AnnuallyBoldedDates</font> collections
are rendered just the same as those not added to any of the collections. The same
code works just fine on Windows XP and causes those dates to be rendered bold. The
only workaround i've managed to <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2296827&amp;SiteID=1">find</a> is
disabling visual styles in the application, i.e. commenting out the first line in
the <font face="Courier New">Program.Main()</font> method of a new Windows Application:
</p>
        <p>
          <font face="Courier New">Application.EnableVisualStyles();</font>
        </p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=ec1b3869-796e-4d12-8d41-614bcb51aad5" />
      </body>
      <title>MonthCalendar BoldedDates in Windows Vista</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,ec1b3869-796e-4d12-8d41-614bcb51aad5.aspx</guid>
      <link>http://www.damirscorner.com/MonthCalendarBoldedDatesInWindowsVista.aspx</link>
      <pubDate>Mon, 14 Apr 2008 19:54:58 GMT</pubDate>
      <description>&lt;p&gt;
The &lt;font face="Courier New"&gt;MonthCalendar&lt;/font&gt; control's &lt;font face="Courier New"&gt;BoldedDates&lt;/font&gt; functionality
doesn't appear to work properly on Windows Vista. The dates added to any of the &lt;font face="Courier New"&gt;BoldedDates&lt;/font&gt;, &lt;font face="Courier New"&gt;MonthlyBoldedDates&lt;/font&gt; and &lt;font face="Courier New"&gt;AnnuallyBoldedDates&lt;/font&gt; collections
are rendered just the same as those not added to any of the collections. The same
code works just fine on Windows XP and causes those dates to be rendered bold. The
only workaround i've managed to &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2296827&amp;amp;SiteID=1"&gt;find&lt;/a&gt; is
disabling visual styles in the application, i.e. commenting out the first line in
the &lt;font face="Courier New"&gt;Program.Main()&lt;/font&gt; method of a new Windows Application:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Application.EnableVisualStyles();&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=ec1b3869-796e-4d12-8d41-614bcb51aad5" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,ec1b3869-796e-4d12-8d41-614bcb51aad5.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/Vista</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=fcd08df4-c6f8-4a1f-ae1f-c5ed70431510</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,fcd08df4-c6f8-4a1f-ae1f-c5ed70431510.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,fcd08df4-c6f8-4a1f-ae1f-c5ed70431510.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=fcd08df4-c6f8-4a1f-ae1f-c5ed70431510</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Xbox 360 Dashboard update released on 4th December 2007 added support for playing
DivX and XviD videos natively, i.e. without installing <a href="http://www.runtime360.com/projects/transcode-360/">Transcode
360</a> for Windows Media Center. Unfortunatelly this only works for media played
directly from the dashboard and not within Media Center Extender. Since I didn't want
to copy my videos to CDs, DVDs or other external devices, the only thing left to do
was to setup Windows Media Player media sharing which I never had to use before.
</p>
        <p>
This turned out to be more difficult than I expected - the reason being that the media
I wanted to share wasn't stored locally but on a separate file server. By default
such media is not shared and there are few steps one has to follow to make this work,
as thoroughly explained <a href="http://www.microsoft.com/windows/windowsmedia/player/faq/sharing.mspx#q20_17">here</a>:
</p>
        <ul>
          <li>
Enable remote content sharing by adding the following entry into the registry:<br /><font face="Courier New">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\Preferences\HME]<br />
"EnableRemoteContentSharing"=dword:00000001</font></li>
          <li>
Grant anonymous users access to the shared folders on the file server by adding the
read permission on the folder and on the share to the <font face="Courier New">ANONYMOUS
LOGON</font> user 
</li>
          <li>
Modify the file server's group policy to allow anonymous access to the selected shares
by listing them in the <font face="Courier New">Network access: Shares that can be
accessed anonymously</font> policy in the <font face="Courier New">Computer Configuration,
Windows Settings, Security Settings, Local Policies, Security Options</font> branch
of the group policy tree (just run <font face="Courier New">gpedit.msc</font> to start
the Group Policy Object Editor)</li>
        </ul>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=fcd08df4-c6f8-4a1f-ae1f-c5ed70431510" />
      </body>
      <title>Playing DivX and XviD videos natively on Xbox 360</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,fcd08df4-c6f8-4a1f-ae1f-c5ed70431510.aspx</guid>
      <link>http://www.damirscorner.com/PlayingDivXAndXviDVideosNativelyOnXbox360.aspx</link>
      <pubDate>Mon, 31 Dec 2007 11:34:14 GMT</pubDate>
      <description>&lt;p&gt;
The Xbox 360 Dashboard update released on 4th December 2007 added support for playing
DivX and XviD videos natively, i.e. without installing &lt;a href="http://www.runtime360.com/projects/transcode-360/"&gt;Transcode
360&lt;/a&gt; for Windows Media Center. Unfortunatelly this only works for media played
directly from the dashboard and not within Media Center Extender. Since I didn't want
to copy my videos to CDs, DVDs or other external devices, the only thing left to do
was to setup Windows Media Player media sharing which I never had to use before.
&lt;/p&gt;
&lt;p&gt;
This turned out to be more difficult than I expected - the reason being that the media
I wanted to share wasn't stored locally but on a separate file server. By default
such media is not shared and there are few steps one has to follow to make this work,
as thoroughly explained &lt;a href="http://www.microsoft.com/windows/windowsmedia/player/faq/sharing.mspx#q20_17"&gt;here&lt;/a&gt;:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Enable remote content sharing by adding the following entry into the registry:&lt;br&gt;
&lt;font face="Courier New"&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\Preferences\HME]&lt;br&gt;
"EnableRemoteContentSharing"=dword:00000001&lt;/font&gt; 
&lt;li&gt;
Grant anonymous users access to the shared folders on the file server by adding the
read permission on the folder and on the share to the &lt;font face="Courier New"&gt;ANONYMOUS
LOGON&lt;/font&gt; user 
&lt;li&gt;
Modify the file server's group policy to allow anonymous access to the selected shares
by listing them in the &lt;font face="Courier New"&gt;Network access: Shares that can be
accessed anonymously&lt;/font&gt; policy in the &lt;font face="Courier New"&gt;Computer Configuration,
Windows Settings, Security Settings, Local Policies, Security Options&lt;/font&gt; branch
of the group policy tree (just run &lt;font face="Courier New"&gt;gpedit.msc&lt;/font&gt; to start
the Group Policy Object Editor)&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=fcd08df4-c6f8-4a1f-ae1f-c5ed70431510" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,fcd08df4-c6f8-4a1f-ae1f-c5ed70431510.aspx</comments>
      <category>Personal</category>
      <category>Personal/Software</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In my opinion RSACryptoServiceProvider class is seriously under-documented in MSDN.
Since there is also no abundance of examples on the web, I spent more time than I
should figuring out how to use it correctly. For future reference I'm listing below
the solution to two problems I had.
</p>
        <p>
The maximum byte array length for encrypting without OAEP padding is Modulus size
- 11 which is written somewhere in the <a href="http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.encrypt.aspx">Encrypt()
method documentation</a>. If you pass it a larger array it will return a not so informative
Unspecified error. To encrypt a larger chunk of data you have to split it in smaller
parts, encrypt them individually and concatenate them back together. You have to do
the same when decrypting the data, with the only difference that each part has the
size of Modulus in stead of Modulus - 11. To get the modulus size you can use the
following piece of code (rsa is an instance of RSACryptoServiceProvider):
</p>
        <div class="CodeFormatContainer">
          <pre class="csharpcode">RSAParameters rsaParams = rsa.ExportParameters(<span class="kwrd">false</span>); <span class="kwrd">int</span> modulusSize
= rsaParams.Modulus.Length; </pre>
        </div>
        <p>
Each time you instantiate RSACryptoServiceProvider it generates a new pair of keys.
If you want to use existing ones, you can import them by calling:
</p>
        <div class="CodeFormatContainer">
          <pre class="csharpcode">rsa.FromXmlString(key);</pre>
        </div>
        <p>
The key parameter is a string with the XML representation of the keys. You can get
it by calling the ToXmlString() method once and storing its results. It's only parameter
specifies whether to also export the private key. I guess I don't have to remind you
that you need the private key only for decryption and that you should always keep
it private for the encryption to make any sense at all. 
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18" />
      </body>
      <title>Notes about RSACryptoServiceProvider</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18.aspx</guid>
      <link>http://www.damirscorner.com/NotesAboutRSACryptoServiceProvider.aspx</link>
      <pubDate>Sat, 24 Nov 2007 16:31:53 GMT</pubDate>
      <description>&lt;p&gt;
In my opinion RSACryptoServiceProvider class is seriously under-documented in MSDN.
Since there is also no abundance of examples on the web, I spent more time than I
should figuring out how to use it correctly. For future reference I'm listing below
the solution to two problems I had.
&lt;/p&gt;
&lt;p&gt;
The maximum byte array length for encrypting without OAEP padding is Modulus size
- 11 which is written somewhere in the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.encrypt.aspx"&gt;Encrypt()
method documentation&lt;/a&gt;. If you pass it a larger array it will return a not so informative
Unspecified error. To encrypt a larger chunk of data you have to split it in smaller
parts, encrypt them individually and concatenate them back together. You have to do
the same when decrypting the data, with the only difference that each part has the
size of Modulus in stead of Modulus - 11. To get the modulus size you can use the
following piece of code (rsa is an instance of RSACryptoServiceProvider):
&lt;/p&gt;
&lt;div class="CodeFormatContainer"&gt;&lt;pre class="csharpcode"&gt;RSAParameters rsaParams = rsa.ExportParameters(&lt;span class="kwrd"&gt;false&lt;/span&gt;); &lt;span class="kwrd"&gt;int&lt;/span&gt; modulusSize
= rsaParams.Modulus.Length; &lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Each time you instantiate RSACryptoServiceProvider it generates a new pair of keys.
If you want to use existing ones, you can import them by calling:
&lt;/p&gt;
&lt;div class="CodeFormatContainer"&gt;&lt;pre class="csharpcode"&gt;rsa.FromXmlString(key);&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
The key parameter is a string with the XML representation of the keys. You can get
it by calling the ToXmlString() method once and storing its results. It's only parameter
specifies whether to also export the private key. I guess I don't have to remind you
that you need the private key only for decryption and that you should always keep
it private for the encryption to make any sense at all. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,eeb23ba8-38df-4a7b-8b2e-3fd5132e8a18.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=52003afd-e963-49d3-a950-388855fed432</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,52003afd-e963-49d3-a950-388855fed432.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,52003afd-e963-49d3-a950-388855fed432.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=52003afd-e963-49d3-a950-388855fed432</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Is the code below correct? Will inputString and outputString be equal?
</p>
        <div class="CodeFormatContainer">
          <div class="CodeFormatContainer">
            <pre class="csharpcode">
              <span class="kwrd">string</span> inputString
= <span class="str">"The text to compress and decompress"</span>; <span class="kwrd">byte</span>[]
inputArray = Encoding.UTF8.GetBytes(inputString); MemoryStream stream = <span class="kwrd">new</span> MemoryStream();
DeflateStream compressionStream = <span class="kwrd">new</span> DeflateStream(stream,
CompressionMode.Compress); compressionStream.Write(inputArray, 0, inputArray.Length);
compressionStream.Flush(); stream.Position = 0; DeflateStream decompressionStream
= <span class="kwrd">new</span> DeflateStream(stream, CompressionMode.Decompress); <span class="kwrd">byte</span>[]
outputArray = <span class="kwrd">new</span><span class="kwrd">byte</span>[inputArray.Length];
decompressionStream.Read(outputArray, 0, outputArray.Length); <span class="kwrd">string</span> outputString
= Encoding.UTF8.GetString(outputArray); Console.WriteLine(outputString == inputString);
Console.ReadLine(); </pre>
          </div>
        </div>
        <p>
As it turns out, they won't. The reason for it being that compressionStream.Close()
was not called before reading from stream started. Calling compressionStream.Flush()
is not enough in this case. I haven't managed to find this documented anywhere but
the example in the <a href="http://msdn2.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx">DeflateStream
documentation</a> does it correctly. You can find the fixed code below. Notice the
additional last parameter in the first call to the DeflateStream constructor. Without
it stream will also be closed when compressionStream gets closed.
</p>
        <div class="CodeFormatContainer">
          <div class="CodeFormatContainer">
            <pre class="csharpcode">
              <span class="kwrd">string</span> inputString
= <span class="str">"The text to compress and decompress"</span>; <span class="kwrd">byte</span>[]
inputArray = Encoding.UTF8.GetBytes(inputString); MemoryStream stream = <span class="kwrd">new</span> MemoryStream();
DeflateStream compressionStream = <span class="kwrd">new</span> DeflateStream(stream,
CompressionMode.Compress, <span class="kwrd">true</span>); compressionStream.Write(inputArray,
0, inputArray.Length); compressionStream.Close(); stream.Position = 0; DeflateStream
decompressionStream = <span class="kwrd">new</span> DeflateStream(stream, CompressionMode.Decompress); <span class="kwrd">byte</span>[]
outputArray = <span class="kwrd">new</span><span class="kwrd">byte</span>[inputArray.Length];
decompressionStream.Read(outputArray, 0, outputArray.Length); <span class="kwrd">string</span> outputString
= Encoding.UTF8.GetString(outputArray); Console.WriteLine(outputString == inputString);
Console.ReadLine(); </pre>
          </div>
        </div>
        <p>
Thanks once again to my coworker for suggesting this when I was already running out
of ideas.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=52003afd-e963-49d3-a950-388855fed432" />
      </body>
      <title>Always close DeflateStream before reading results</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,52003afd-e963-49d3-a950-388855fed432.aspx</guid>
      <link>http://www.damirscorner.com/AlwaysCloseDeflateStreamBeforeReadingResults.aspx</link>
      <pubDate>Sat, 24 Nov 2007 15:44:37 GMT</pubDate>
      <description>&lt;p&gt;
Is the code below correct? Will inputString and outputString be equal?
&lt;/p&gt;
&lt;div class="CodeFormatContainer"&gt;
&lt;div class="CodeFormatContainer"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; inputString
= &lt;span class="str"&gt;"The text to compress and decompress"&lt;/span&gt;; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[]
inputArray = Encoding.UTF8.GetBytes(inputString); MemoryStream stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream();
DeflateStream compressionStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; DeflateStream(stream,
CompressionMode.Compress); compressionStream.Write(inputArray, 0, inputArray.Length);
compressionStream.Flush(); stream.Position = 0; DeflateStream decompressionStream
= &lt;span class="kwrd"&gt;new&lt;/span&gt; DeflateStream(stream, CompressionMode.Decompress); &lt;span class="kwrd"&gt;byte&lt;/span&gt;[]
outputArray = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[inputArray.Length];
decompressionStream.Read(outputArray, 0, outputArray.Length); &lt;span class="kwrd"&gt;string&lt;/span&gt; outputString
= Encoding.UTF8.GetString(outputArray); Console.WriteLine(outputString == inputString);
Console.ReadLine(); &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
As it turns out, they won't. The reason for it being that compressionStream.Close()
was not called before reading from stream started. Calling compressionStream.Flush()
is not enough in this case. I haven't managed to find this documented anywhere but
the example in the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx"&gt;DeflateStream
documentation&lt;/a&gt; does it correctly. You can find the fixed code below. Notice the
additional last parameter in the first call to the DeflateStream constructor. Without
it stream will also be closed when compressionStream gets closed.
&lt;/p&gt;
&lt;div class="CodeFormatContainer"&gt;
&lt;div class="CodeFormatContainer"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; inputString
= &lt;span class="str"&gt;"The text to compress and decompress"&lt;/span&gt;; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[]
inputArray = Encoding.UTF8.GetBytes(inputString); MemoryStream stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream();
DeflateStream compressionStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; DeflateStream(stream,
CompressionMode.Compress, &lt;span class="kwrd"&gt;true&lt;/span&gt;); compressionStream.Write(inputArray,
0, inputArray.Length); compressionStream.Close(); stream.Position = 0; DeflateStream
decompressionStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; DeflateStream(stream, CompressionMode.Decompress); &lt;span class="kwrd"&gt;byte&lt;/span&gt;[]
outputArray = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[inputArray.Length];
decompressionStream.Read(outputArray, 0, outputArray.Length); &lt;span class="kwrd"&gt;string&lt;/span&gt; outputString
= Encoding.UTF8.GetString(outputArray); Console.WriteLine(outputString == inputString);
Console.ReadLine(); &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Thanks once again to my coworker for suggesting this when I was already running out
of ideas.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=52003afd-e963-49d3-a950-388855fed432" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,52003afd-e963-49d3-a950-388855fed432.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=90fc52c2-c73a-4709-900b-6f96fb4c9f1e</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,90fc52c2-c73a-4709-900b-6f96fb4c9f1e.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,90fc52c2-c73a-4709-900b-6f96fb4c9f1e.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=90fc52c2-c73a-4709-900b-6f96fb4c9f1e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Not so long ago I've been called to my boss's office to prevent him losing unsaved
work in a PowerPoint presentation. It turned out that when he tried to save the file
to a new location the message box with the overwrite warning for some reason didn't
render completely and it was impossible to close it. As it turned out at the end I
could have just killed the application and restart it, since the AutoRecover feature
kicked in and offered a version of the file with all changes applied.
</p>
        <p>
But just to be on the save side I wanted to copy the AutoRecover files to a save location
before actually killing the application. But unlike Word or Excel where the location
of these files is set in the options, PowerPoint does not have such an option. After
some googling I finally stumbled across <a href="http://office.microsoft.com/en-us/help/HA101578851033.aspx">a
page</a>, correctly stating that the files are stored in the %temp% folder and named
ppt*.tmp. I decided to publish this info here just in case I need it again.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=90fc52c2-c73a-4709-900b-6f96fb4c9f1e" />
      </body>
      <title>Location of PowerPoint AutoRecover files</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,90fc52c2-c73a-4709-900b-6f96fb4c9f1e.aspx</guid>
      <link>http://www.damirscorner.com/LocationOfPowerPointAutoRecoverFiles.aspx</link>
      <pubDate>Sat, 24 Nov 2007 14:11:03 GMT</pubDate>
      <description>&lt;p&gt;
Not so long ago I've been called to my boss's office to prevent him losing unsaved
work in a PowerPoint presentation. It turned out that when he tried to save the file
to a new location the message box with the overwrite warning for some reason didn't
render completely and it was impossible to close it. As it turned out at the end I
could have just killed the application and restart it, since the AutoRecover feature
kicked in and offered a version of the file with all changes applied.
&lt;/p&gt;
&lt;p&gt;
But just to be on the save side I wanted to copy the AutoRecover files to a save location
before actually killing the application. But unlike Word or Excel where the location
of these files is set in the options, PowerPoint does not have such an option. After
some googling I finally stumbled across &lt;a href="http://office.microsoft.com/en-us/help/HA101578851033.aspx"&gt;a
page&lt;/a&gt;, correctly stating that the files are stored in the %temp% folder and named
ppt*.tmp. I decided to publish this info here just in case I need it again.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=90fc52c2-c73a-4709-900b-6f96fb4c9f1e" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,90fc52c2-c73a-4709-900b-6f96fb4c9f1e.aspx</comments>
      <category>Personal</category>
      <category>Personal/Software</category>
    </item>
  </channel>
</rss>