<?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>Advanced Software Engineering &#187; windows</title>
	<atom:link href="http://www.gabrielgonzalezgarcia.com/tag/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gabrielgonzalezgarcia.com</link>
	<description>or something like that</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:19:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python: Simple Socket Server</title>
		<link>http://www.gabrielgonzalezgarcia.com/2010/09/27/python-simple-socket-server/</link>
		<comments>http://www.gabrielgonzalezgarcia.com/2010/09/27/python-simple-socket-server/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 19:29:44 +0000</pubDate>
		<dc:creator>Gabriel Gonzalez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[UNIX world]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.advansen.com/?p=148</guid>
		<description><![CDATA[The simplest socket server, don&#8217;t know why but I always forget how bind is used in python. import socket &#160; sock = socket.socket&#40;socket.AF_INET, socket.SOCK_STREAM&#41; sock.bind&#40;&#40;&#34;127.0.0.1&#34;, 1024 + 666&#41;&#41; sock.listen&#40;5&#41; &#160; &#160; client, details = sock.accept&#40;&#41; while 1: data = client.recv&#40;1024&#41; print &#34;data : %s&#34; % repr&#40;data&#41;]]></description>
			<content:encoded><![CDATA[<p>The simplest socket server, don&#8217;t know why but I always forget how bind is used in python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
&nbsp;
sock = <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">bind</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;127.0.0.1&quot;</span>, <span style="color: #ff4500;">1024</span> + <span style="color: #ff4500;">666</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">listen</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
client, details = sock.<span style="color: black;">accept</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
    data = client.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;data : %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gabrielgonzalezgarcia.com/2010/09/27/python-simple-socket-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: POST XML over HTTP</title>
		<link>http://www.gabrielgonzalezgarcia.com/2010/07/22/python-post-xml-over-http/</link>
		<comments>http://www.gabrielgonzalezgarcia.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 [...]]]></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="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">httplib</span>, <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
params = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'q'</span>: <span style="color: #483d8b;">'login'</span>, <span style="color: #483d8b;">'email'</span>: <span style="color: #483d8b;">'juasjuas@lol.com'</span>, <span style="color: #483d8b;">'pwd'</span>: <span style="color: #483d8b;">'lala'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
&nbsp;
conn = <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPConnection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;my.lolizator.com:80&quot;</span><span style="color: black;">&#41;</span>
conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GET&quot;</span>, <span style="color: #483d8b;">&quot;/cmd.php?&quot;</span>+params<span style="color: black;">&#41;</span>
response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> response.<span style="color: black;">status</span>, response.<span style="color: black;">reason</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#data = response.read()</span>
<span style="color: #808080; font-style: italic;">#print data</span>
&nbsp;
cookies = response.<span style="color: black;">getheader</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;set-cookie&quot;</span><span style="color: black;">&#41;</span>
m = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.*PHPSESSID=([a-zA-Z0-9]+);.*'</span>, cookies<span style="color: black;">&#41;</span>
session = m.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;session %s&quot;</span> <span style="color: #66cc66;">%</span> session
XML=<span style="color: #483d8b;">'&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;'</span>
params = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'q'</span>: <span style="color: #483d8b;">'set'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
headers = <span style="color: black;">&#123;</span> <span style="color: #483d8b;">&quot;Cookie&quot;</span>: <span style="color: #483d8b;">&quot;PHPSESSID=&quot;</span> + session, <span style="color: #483d8b;">&quot;Content-type&quot;</span>: <span style="color: #483d8b;">&quot;text/xml&quot;</span>,
            <span style="color: #483d8b;">&quot;Content-Length&quot;</span>: <span style="color: #483d8b;">&quot;%d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>XML<span style="color: black;">&#41;</span><span style="color: black;">&#125;</span>
conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;POST&quot;</span>, <span style="color: #483d8b;">&quot;/cmd.php?&quot;</span>+params, <span style="color: #483d8b;">&quot;&quot;</span>, headers<span style="color: black;">&#41;</span>
conn.<span style="color: black;">send</span><span style="color: black;">&#40;</span>XML<span style="color: black;">&#41;</span>
response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> response.<span style="color: black;">status</span>, response.<span style="color: black;">reason</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gabrielgonzalezgarcia.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.gabrielgonzalezgarcia.com/2010/01/25/twitter-internal-fragmentation-python-twitter/</link>
		<comments>http://www.gabrielgonzalezgarcia.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 [...]]]></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="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span>  twitter
<span style="color: #ff7700;font-weight:bold;">import</span>  <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">2</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span>   <span style="color: #483d8b;">&quot;Provide a Twitter Username as Argument&quot;</span>
        exit<span style="color: black;">&#40;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
api = twitter.<span style="color: black;">Api</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
st = api.<span style="color: black;">GetUserTimeline</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #008000;">sum</span> = <span style="color: #ff4500;">0.0</span>
<span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> st:
        <span style="color: #008000;">sum</span> += <span style="color: black;">&#40;</span><span style="color: #ff4500;">140.0</span> - <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s.<span style="color: black;">text</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;utf-8&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">140.0</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s internal fragmentation is %.2f%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #008000;">round</span><span style="color: black;">&#40;</span><span style="color: #008000;">sum</span> / <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>st<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">100</span>, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;%&quot;</span><span style="color: black;">&#41;</span></pre></div></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.gabrielgonzalezgarcia.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.gabrielgonzalezgarcia.com/2009/09/21/squid-active-directory/</link>
		<comments>http://www.gabrielgonzalezgarcia.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 [...]]]></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="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">subprocess</span>, <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">re</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> active_directory
&nbsp;
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> :
&nbsp;
	squid = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>squid<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span>:
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
	m = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'(?&amp;lt;=%5C)<span style="color: #000099; font-weight: bold;">\w</span>+'</span>, squid<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
	username = m.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
	m = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'(?&amp;lt;= )[<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\.</span>]+'</span>, squid<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
	checkgroup = m.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
	ret = <span style="color: #483d8b;">&quot;ERR&quot;</span><span style="color: #66cc66;">;</span>
&nbsp;
	<span style="color: #dc143c;">user</span> = active_directory.<span style="color: black;">find_user</span><span style="color: black;">&#40;</span>username<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> group <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">user</span>.<span style="color: black;">memberOf</span>:
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span>group.<span style="color: black;">cn</span>, checkgroup<span style="color: black;">&#41;</span>  == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
&nbsp;
			ret = <span style="color: #483d8b;">&quot;OK&quot;</span>
			<span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">print</span>	ret + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">;</span>
&nbsp;
	<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></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.gabrielgonzalezgarcia.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.gabrielgonzalezgarcia.com/2009/09/07/creating-an-installer-using-nsis-iii/</link>
		<comments>http://www.gabrielgonzalezgarcia.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.gabrielgonzalezgarcia.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.gabrielgonzalezgarcia.com/2009/09/02/creating-an-installer-using-nsis-ii/</link>
		<comments>http://www.gabrielgonzalezgarcia.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 [...]]]></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.gabrielgonzalezgarcia.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.gabrielgonzalezgarcia.com/2009/09/01/creating-an-installer-using-nsis-i/</link>
		<comments>http://www.gabrielgonzalezgarcia.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 [...]]]></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.gabrielgonzalezgarcia.com/2009/09/01/creating-an-installer-using-nsis-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

