<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mostly Software Engineering &#187; windows</title>
	<atom:link href="http://www.advansen.com/tag/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.advansen.com</link>
	<description>Gabriel Gonzalez&#039;s notebook</description>
	<lastBuildDate>Thu, 22 Jul 2010 13:47:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python: POST XML over HTTP</title>
		<link>http://www.advansen.com/2010/07/22/python-post-xml-over-http/</link>
		<comments>http://www.advansen.com/2010/07/22/python-post-xml-over-http/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 13:46:26 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=138</guid>
		<description><![CDATA[Short post to remind myself how to do HTTP requests using python, really easy stuff that I quickly forget.
Straight forward example using httplib and urllib from python. In the example I just perform some kind of login request retrieve the session id and then other request sending XML data using POST.
Code! Feel free to send [...]]]></description>
			<content:encoded><![CDATA[<p>Short post to remind myself how to do HTTP requests using python, really easy stuff that I quickly forget.</p>
<p>Straight forward example using httplib and urllib from python. In the example I just perform some kind of login request retrieve the session id and then other request sending XML data using POST.</p>
<p>Code! Feel free to send improvements</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">import</span> <span class="kw3">httplib</span>, <span class="kw3">urllib</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">import</span> <span class="kw3">re</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">params = <span class="kw3">urllib</span>.<span class="me1">urlencode</span><span class="br0">&#40;</span><span class="br0">&#123;</span><span class="st0">&#8216;q&#8217;</span>: <span class="st0">&#8216;login&#8217;</span>, <span class="st0">&#8216;email&#8217;</span>: <span class="st0">&#8216;juasjuas@lol.com&#8217;</span>, <span class="st0">&#8216;pwd&#8217;</span>: <span class="st0">&#8216;lala&#8217;</span><span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">conn = <span class="kw3">httplib</span>.<span class="me1">HTTPConnection</span><span class="br0">&#40;</span><span class="st0">&quot;my.lolizator.com:80&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">conn.<span class="me1">request</span><span class="br0">&#40;</span><span class="st0">&quot;GET&quot;</span>, <span class="st0">&quot;/cmd.php?&quot;</span>+params<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">response = conn.<span class="me1">getresponse</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">print</span> response.<span class="me1">status</span>, response.<span class="me1">reason</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#data = response.read()</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#print data</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">cookies = response.<span class="me1">getheader</span><span class="br0">&#40;</span><span class="st0">&quot;set-cookie&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">m = <span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">&#8216;.*PHPSESSID=([a-zA-Z0-9]+);.*&#8217;</span>, cookies<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">session = m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">print</span> <span class="st0">&quot;session %s&quot;</span> % session</div>
</li>
<li class="li1">
<div class="de1">XML=<span class="st0">&#8216;&lt;tag1 name=&quot;testgroup&quot;&gt;&lt;tag2 id=&quot;12&quot; type=&quot;3&quot;&gt;&lt;tag3 id=&quot;1&quot;&gt;aaa&lt;/tag3&gt;&lt;/tag2&gt;&lt;/tag1&gt;&#8217;</span></div>
</li>
<li class="li2">
<div class="de2">params = <span class="kw3">urllib</span>.<span class="me1">urlencode</span><span class="br0">&#40;</span><span class="br0">&#123;</span><span class="st0">&#8216;q&#8217;</span>: <span class="st0">&#8217;set&#8217;</span><span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">headers = <span class="br0">&#123;</span> <span class="st0">&quot;Cookie&quot;</span>: <span class="st0">&quot;PHPSESSID=&quot;</span> + session, <span class="st0">&quot;Content-type&quot;</span>: <span class="st0">&quot;text/xml&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Content-Length&quot;</span>: <span class="st0">&quot;%d&quot;</span> % <span class="kw2">len</span><span class="br0">&#40;</span>XML<span class="br0">&#41;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">conn.<span class="me1">request</span><span class="br0">&#40;</span><span class="st0">&quot;POST&quot;</span>, <span class="st0">&quot;/cmd.php?&quot;</span>+params, <span class="st0">&quot;&quot;</span>, headers<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">conn.<span class="me1">send</span><span class="br0">&#40;</span>XML<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">response = conn.<span class="me1">getresponse</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">print</span> response.<span class="me1">status</span>, response.<span class="me1">reason</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">print</span> response.<span class="me1">read</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">conn.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.advansen.com/2010/07/22/python-post-xml-over-http/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Internal Fragmentation: Python + Twitter</title>
		<link>http://www.advansen.com/2010/01/25/twitter-internal-fragmentation-python-twitter/</link>
		<comments>http://www.advansen.com/2010/01/25/twitter-internal-fragmentation-python-twitter/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 09:32:55 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[open source tools]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=129</guid>
		<description><![CDATA[As a toy project to play a little bit more with Python and accessing Twitter, I came out with the idea of calculating the Internal Fragmentation of user&#8217;s tweet. 
To interface with Twitter services I used the Twitter extension located at http://code.google.com/p/python-twitter/, which has a pretty straightforward API.
The script shown below gives you back what [...]]]></description>
			<content:encoded><![CDATA[<p>As a toy project to play a little bit more with <strong>Python </strong>and accessing <strong>Twitter</strong>, I came out with the idea of calculating the <a href="http://en.wikipedia.org/wiki/Fragmentation_(computer)">Internal Fragmentation</a> of user&#8217;s tweet. </p>
<p>To interface with Twitter services I used the <a href="http://code.google.com/p/python-twitter/">Twitter extension</a> located at <a href="http://code.google.com/p/python-twitter/">http://code.google.com/p/python-twitter/</a>, which has a pretty straightforward API.</p>
<p>The script shown below gives you back what average percentage of your last 20 tweets have been wasted.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">import</span> &nbsp;twitter</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">import</span> &nbsp;<span class="kw3">sys</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">if</span> <span class="kw2">len</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#41;</span> != <span class="nu0">2</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span> &nbsp; <span class="st0">&quot;Provide a Twitter Username as Argument&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; exit<span class="br0">&#40;</span><span class="nu0">-1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">api = twitter.<span class="me1">Api</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">st = api.<span class="me1">GetUserTimeline</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">sum</span> = <span class="nu0">0.0</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> s <span class="kw1">in</span> st:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">sum</span> += <span class="br0">&#40;</span><span class="nu0">140.0</span> &#8211; <span class="kw2">len</span><span class="br0">&#40;</span>s.<span class="me1">text</span>.<span class="me1">encode</span><span class="br0">&#40;</span><span class="st0">&quot;utf-8&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>/<span class="nu0">140.0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">print</span> <span class="st0">&quot;%s internal fragmentation is %.2f%s&quot;</span> % <span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>, <span class="kw2">round</span><span class="br0">&#40;</span><span class="kw2">sum</span> / <span class="kw2">len</span><span class="br0">&#40;</span>st<span class="br0">&#41;</span> * <span class="nu0">100</span>, <span class="nu0">2</span><span class="br0">&#41;</span>, <span class="st0">&quot;%&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>And now some results:<br />
<code><br />
$ python twinternal.py GabrielGonzalez<br />
GabrielGonzalez internal fragmentation is 39.89%<br />
$ python twinternal.py 48bits<br />
48bits internal fragmentation is 36.79%<br />
$ python twinternal.py reversemode<br />
reversemode internal fragmentation is 38.72%<br />
$ python twinternal.py aramosf<br />
aramosf internal fragmentation is 32.41%<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.advansen.com/2010/01/25/twitter-internal-fragmentation-python-twitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQUID + Active Directory</title>
		<link>http://www.advansen.com/2009/09/21/squid-active-directory/</link>
		<comments>http://www.advansen.com/2009/09/21/squid-active-directory/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 10:59:54 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQUID]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=114</guid>
		<description><![CDATA[A few post ago I wrote about integrating SQUID and Active Directory in order to allow/deny users to access specific webpages depeding on the groups a user belongs.
The windows package of Squid comes with several external programs which can be used as external ACLs which allow you to query the local Active Directory in order [...]]]></description>
			<content:encoded><![CDATA[<p>A few post ago I wrote about integrating <strong><em>SQUID </em></strong>and <strong><em>Active Directory </em></strong>in order to allow/deny users to access specific webpages depeding on the groups a user belongs.</p>
<p>The windows package of <strong><em>Squid </em></strong>comes with several external programs which can be used as <em><strong>external ACL</strong></em>s which allow you to query the local Active Directory in order to obtain access or not. The one dealing with users and groups is called <em><strong>mswin_check_ad_group.exe </strong><span style="font-style: normal;">which, as all the external ACLs, reads the standard input looking for a user and a group and return whether the user belongs to the given group.</span></em></p>
<p><em><span style="font-style: normal;">This is fine and pretty straight forward it has a PROBLEM, it only works with Groups with scope set to &#8220;Domain Local&#8221;; which turn into a drawback when your users belong to Groups with Global Scope. I haven&#8217;t found any documentation explaining how to achive this so I have created a simple external ACL to peform this task in python.</span></em></p>
<p><em><span style="font-style: normal;">You only need to download <a title="pywin32" href="http://sourceforge.net/projects/pywin32/">pywin32 </a>and the <a title="Active Directory for Python" href="http://timgolden.me.uk/python/downloads/active_directory-0.6.7.zip">active directory plugin</a> for python. After installing just use the following code, which will return OK IFF the user belongs to the given group (non matter which scope):</span></em></p>
<p><em><span style="font-style: normal;"><span id="more-114"></span></span></em></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">import</span> <span class="kw3">os</span>, <span class="kw3">subprocess</span>, <span class="kw3">sys</span>, <span class="kw3">re</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">import</span> active_directory</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">while</span> <span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; squid = <span class="kw3">sys</span>.<span class="me1">stdin</span>.<span class="kw3">readline</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="kw2">len</span><span class="br0">&#40;</span>squid<span class="br0">&#41;</span> == <span class="nu0">0</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; m = <span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">&#8216;(?&lt;=%5C)<span class="es0">\w</span>+&#8217;</span>, squid<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; username = m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; m = <span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">&#8216;(?&lt;= )[<span class="es0">\w</span><span class="es0">\.</span>]+&#8217;</span>, squid<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; checkgroup = m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; ret = <span class="st0">&quot;ERR&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">user</span> = active_directory.<span class="me1">find_user</span><span class="br0">&#40;</span>username<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> group <span class="kw1">in</span> <span class="kw3">user</span>.<span class="me1">memberOf</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw2">cmp</span><span class="br0">&#40;</span>group.<span class="me1">cn</span>, checkgroup<span class="br0">&#41;</span> &nbsp;== <span class="nu0">0</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = <span class="st0">&quot;OK&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span>&nbsp; &nbsp;ret + <span class="st0">&quot;<span class="es0">\r</span><span class="es0">\n</span>&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">sys</span>.<span class="me1">stdout</span>.<span class="me1">flush</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<div><span style="font-style: normal;">I am new to the Python world so, for sure, this little thing can be improved, feel free to comment anything.</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.advansen.com/2009/09/21/squid-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Installer Using NSIS (III)</title>
		<link>http://www.advansen.com/2009/09/07/creating-an-installer-using-nsis-iii/</link>
		<comments>http://www.advansen.com/2009/09/07/creating-an-installer-using-nsis-iii/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 09:32:45 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[NSIS]]></category>
		<category><![CDATA[open source tools]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=104</guid>
		<description><![CDATA[In this last post about NSIS I am going to describe how to use some of the most useful plugins which will allow you create a pretty decent and featurefull installer for windows.

Checking for adminstrator privileges:

 userInfo::getAccountType
 Pop $0
 StrCmp $0 &#8220;Admin&#8221; +3
 
 MessageBox MB_OK &#8220;Debe tener privilegios de administrador para correr este programa [...]]]></description>
			<content:encoded><![CDATA[<p>In this last post about <strong><em><a title="NSIS homepage" href="http://nsis.sourceforge.net/Main_Page">NSIS</a></em></strong> I am going to describe how to use some of the most useful plugins which will allow you create a pretty decent and featurefull<strong><em> installer for windows</em></strong>.</p>
<ul>
<li>Checking for adminstrator privileges:</li>
</ul>
<blockquote><p><span style="white-space: pre;"> </span>userInfo::getAccountType</p>
<p><span style="white-space: pre;"> </span>Pop $0</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>StrCmp $0 &#8220;Admin&#8221; +3</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>MessageBox MB_OK &#8220;Debe tener privilegios de administrador para correr este programa de instalación: $0&#8243;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Return</div>
<p><span style="white-space: pre;"> </span>StrCmp $0 &#8220;Admin&#8221; +3</p>
<p><span style="white-space: pre;"> </span>MessageBox MB_OK &#8220;You need Administrator privileges: $0&#8243;</p>
<p><span style="white-space: pre;"> </span>Return</p></blockquote>
<p>This chunk of code will pop up a windows with the propoer notification. The <em>StrCmp </em>sentence compares the <em>$0</em> variable poped from the stack against <em>&#8220;Admin&#8221; </em>and if they are equal continue the execution with the 3rd line of code, the one below Return.</p>
<ul>
<li>Downloading and Executing, e.g. an external installer:</li>
</ul>
<blockquote><p><span style="white-space: pre;"> </span>NSISdl::download /TIMEOUT=30000 &#8220;http://www.advansen.com/this/is/a/test/advansen.msi&#8221; &#8220;$INSTDIR\advansen.msi&#8221;</p>
<p><span style="white-space: pre;"> </span>Pop $R0 ;Get the return value</p>
<p><span style="white-space: pre;"> </span>StrCmp $R0 &#8220;success&#8221; +3</p>
<p><span style="white-space: pre;"> </span>MessageBox MB_OK &#8220;Download failed: $R0&#8243;</p>
<p><span style="white-space: pre;"> </span>Quit</p>
<p><span style="white-space: pre;"> </span>ExecWait  &#8217;&#8221;msiexec&#8221; /i &#8220;$INSTDIR\advansen.msi&#8221; /quiet&#8217;</p></blockquote>
<p><span id="more-104"></span></p>
<ul>
<li>Unziping :</li>
</ul>
<p>To use the unzip feature you need to download the <a href="http://nsis.sourceforge.net/ZipDLL_plug-in">unzip external plugin</a>, follow the installation guidelines (basically copying the dll to the plugins directory) and that&#8217;s it.</p>
<blockquote><p><span style="white-space: pre;"> </span>nsisunz::Unzip &#8220;$INSTDIR\squid.zip&#8221; &#8220;C:\&#8221;</p>
<p><span style="white-space: pre;"> </span>Pop $R0</p>
<p><span style="white-space: pre;"> </span>StrCmp $R0 &#8220;success&#8221; +2</p>
<p><span style="white-space: pre;"> </span>DetailPrint &#8220;$R0&#8243;</p></blockquote>
<ul>
<li>Modifying the <a href="http://en.wikipedia.org/wiki/Environment_variable">environment variables</a>:</li>
</ul>
<p>Adding to PATH</p>
<blockquote><p>${EnvVarUpdate} $0 &#8220;PATH&#8221; &#8220;A&#8221; &#8220;HKLM&#8221; &#8220;C:\some\path&#8221;</p></blockquote>
<p>Removing a PATH</p>
<blockquote><p>${un.EnvVarUpdate} $0 &#8220;PATH&#8221; &#8220;R&#8221; &#8220;HKLM&#8221; &#8220;C:\some\path&#8221;</p></blockquote>
<p>To use the code above you also need external help, just download the <a href="http://nsis.sourceforge.net/Environmental_Variables:_append,_prepend,_and_remove_entries#Function_Code">EnvVarUpdate extension</a> and will able to update the $PATH variable easily</p>
]]></content:encoded>
			<wfw:commentRss>http://www.advansen.com/2009/09/07/creating-an-installer-using-nsis-iii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Installer Using NSIS (II)</title>
		<link>http://www.advansen.com/2009/09/02/creating-an-installer-using-nsis-ii/</link>
		<comments>http://www.advansen.com/2009/09/02/creating-an-installer-using-nsis-ii/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 09:08:41 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[NSIS]]></category>
		<category><![CDATA[open source tools]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=92</guid>
		<description><![CDATA[After playing for a few days with NSIS I have manage to create a full features installer which perform all the actions I needed. These are the following:

Download files
Unzip Files to a specific folder
Execute external installers
Modify Environment Variables

Since NSIS supports plug-ins there are quite a few available which provide extra functionalities such as the unzipping [...]]]></description>
			<content:encoded><![CDATA[<p>After playing for a few days with <strong><em>NSIS </em></strong>I have manage to create a full features installer which perform all the actions I needed. These are the following:</p>
<ul>
<li>Download files</li>
<li>Unzip Files to a specific folder</li>
<li>Execute external installers</li>
<li>Modify Environment Variables</li>
</ul>
<p>Since <strong><em>NSIS </em></strong>supports plug-ins there are quite a few available which provide extra functionalities such as the unzipping one.</p>
<p>Before going into these extra features, which will be subject of a new post, I prefer writing down how a more complex script is structure, just to keep in to the future.</p>
<p><strong><em>NSIS</em></strong> is structured in pages (page == panels show each time a &#8220;next button&#8221; is clicked), most of them are predefined, where you can only change tittle or add extra text in them. Following are the pages definition using the <a title="MUI2" href="http://nsis.sourceforge.net/Docs/Modern%20UI/Readme.html">MUI2 interface</a>:</p>
<blockquote><p>!insertmacro MUI_PAGE_LICENSE &#8220;path\to\license.txt&#8221;</p>
<p>!insertmacro MUI_PAGE_COMPONENTS</p>
<p>!insertmacro MUI_PAGE_DIRECTORY</p>
<p>!insertmacro MUI_PAGE_INSTFILES</p></blockquote>
<p><span id="more-92"></span></p>
<p>Except for the components page which is configured using the section described in the previous post.  Each Section name will appear as a component with its corresponding checkbox, groups can also be specified and the code inside each section will be only executed if the component is checked:</p>
<blockquote><p>SectionGroup &#8220;Extra Plug-ins&#8221;</p>
<p>Section &#8220;Spreadsheet&#8221;</p>
<p>SectionEnd</p>
<p>Section &#8220;PDF&#8221;</p>
<p>SectionEnd</p>
<p>SectionGroupEnd</p></blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 176px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">!insertmacro MUI_PAGE_LICENSE &#8220;${NSISDIR}\Docs\Modern UI\License.txt&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 176px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">!insertmacro MUI_PAGE_COMPONENTS</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 176px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">!insertmacro MUI_PAGE_DIRECTORY</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 176px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">!insertmacro MUI_PAGE_INSTFILES</div>
<p><img class="aligncenter size-full wp-image-95" title="components" src="http://www.advansen.com/wp-content/uploads/2009/09/components.PNG" alt="components" width="582" height="367" /></p>
<p>A section declared as follows is executed always :</p>
<blockquote><p>Section &#8220;&#8221;</p>
<p>SectionEnd</p></blockquote>
<p>The next chunk of code creates an entry in the program&#8217;s menu:</p>
<blockquote><p>CreateDirectory &#8220;$SMPROGRAMS\Advansen\&#8221;</p>
<p>CreateShortCut &#8220;$SMPROGRAMS\Advansen\uninstall.lnk&#8221; &#8220;$INSTDIR\uninstall.exe&#8221;</p></blockquote>
<p>And in order to execute external installers or additional programs the <strong><em>ExecWait </em></strong>sentences provides an easy way to achive that. In the next line python uninstaller is called with the quite flag so no window pops up:</p>
<blockquote><p>ExecWait  &#8217;&#8221;msiexec&#8221; /uninstall &#8220;$INSTDIR\python-2.6.2.msi&#8221; /quiet&#8217;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.advansen.com/2009/09/02/creating-an-installer-using-nsis-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Installer Using NSIS (I)</title>
		<link>http://www.advansen.com/2009/09/01/creating-an-installer-using-nsis-i/</link>
		<comments>http://www.advansen.com/2009/09/01/creating-an-installer-using-nsis-i/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 09:00:26 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[NSIS]]></category>
		<category><![CDATA[open source tools]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=85</guid>
		<description><![CDATA[Last week I faced a new problem, I had to program a installer for Windows in order to deploy some software we have produced at work. After a quick googling I found NSIS an installer generator, open source and with a simple scripting language.
NSIS comes with a compiler which parses the sentences writting in its [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I faced a new problem, I had to program a <strong><em>installer for Windows</em></strong> in order to deploy some software we have produced at work. After a quick googling I found <a href="http://nsis.sourceforge.net/Main_Page"><strong><em>NSIS</em></strong></a><strong><em> </em></strong>an installer generator, <strong><em>open source</em></strong> and with a simple scripting language.</p>
<p><em><strong>NSIS </strong></em>comes with a compiler which parses the sentences writting in its own language and produces a pretty decent installer. It also has a <a href="http://nsis.sourceforge.net/NSIS_2">look-and-feeling similar to latets Windows versions</a>, so it was the perfect choice!</p>
<p>The scripting language is really simple, we can generate a simple installer with only the next few lines:</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">outFile &#8220;installer.exe&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">installDir $DESKTOP</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">section</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>userInfo::getAccountType</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>pop $0</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>strCmp $0 &#8220;Admin&#8221; +3</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>messageBox MB_OK &#8220;not admin: $0&#8243;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>return</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>messageBox MB_OK &#8220;is admin&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>setOutPath $INSTDIR</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>file test.txt</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>writeUninstaller $INSTDIR\uninstaller.exe</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>createShortCut &#8220;$SMPROGRAMS\new oxtias.lnk&#8221; &#8220;$INSTDIR\uninstaller.exe&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">sectionEnd</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">section &#8220;Uninstall&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>delete $INSTDIR\uninstaller.exe</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>delete $INSTDIR\test.txt</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>delete &#8220;$SMPROGRAMS\new oxtias.lnk&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">sectionEnd</div>
<blockquote><p>OutFile &#8220;simpleAdvansenInstaller.exe&#8221;</p>
<p>InstallDir $DESKTOP</p>
<p>Section</p>
<p><span style="white-space:pre"> </span>SetOutPath $INSTDIR</p>
<p><span style="white-space:pre"> </span>WriteUninstaller $INSTDIR\uninstaller.exe</p>
<p><span style="white-space:pre"> </span>CreateShortCut &#8220;$SMPROGRAMS\simpleAdvansen.lnk&#8221; &#8220;$INSTDIR\uninstaller.exe&#8221;</p>
<p>SectionEnd</p>
<p>Section &#8220;Uninstall&#8221;</p>
<p><span style="white-space:pre"> </span>Delete $INSTDIR\uninstaller.exe</p>
<p><span style="white-space:pre"> </span>Delete $INSTDIR\test.txt</p>
<p><span style="white-space:pre"> </span>Delete &#8220;$SMPROGRAMS\simpleAdvansen.lnk&#8221;</p>
<p>SectionEnd</p></blockquote>
<p>After compiling the script with the tool NSIS package&#8217;s comes with, two executables are generated:</p>
<blockquote><p>simpleAdvansenInstaller.exe</p></blockquote>
<p>Which will copy the uninstaller.exe to the Installation Dir set up to the Desktop and will add an entry in the Programs Menu for the uninstaller.</p>
<blockquote><p>uninstaller.exe</p></blockquote>
<p>Will delete itself and remove the entry in the Programs Menu.</p>
<p>NOTE: NotePad++ highlights the syntax of <em><strong>NSIS </strong></em>as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.advansen.com/2009/09/01/creating-an-installer-using-nsis-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
