<?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>blog.nicolas.pawlak.fr &#187; Windows</title>
	<atom:link href="http://blog.nicolas.pawlak.fr/categories/systemes-d-exploitation/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicolas.pawlak.fr</link>
	<description>Tux ne sait pas voler, c&#039;est normal : ce n&#039;est pas un pingouin...</description>
	<lastBuildDate>Sun, 31 Jul 2011 14:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Fonction ASP de recherche d&#8217;un utilisateur Active Directory</title>
		<link>http://blog.nicolas.pawlak.fr/2010/07/24/fonction-asp-de-recherche-dun-utilisateur-active-directory/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/07/24/fonction-asp-de-recherche-dun-utilisateur-active-directory/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 09:00:06 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[active]]></category>
		<category><![CDATA[ad]]></category>
		<category><![CDATA[annuaire]]></category>
		<category><![CDATA[attribut]]></category>
		<category><![CDATA[dc]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[fonction]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[ou]]></category>
		<category><![CDATA[recherche]]></category>
		<category><![CDATA[recordset]]></category>
		<category><![CDATA[subtree]]></category>
		<category><![CDATA[utilisateur]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=1161</guid>
		<description><![CDATA[&#60;% Function RechercheUtilisateur&#40;utilisateur, attribut&#41; &#160; 'Déclaration des variables Dim objConn, objRS Dim Base, Filtre, Scope, Cmd Dim ServeurAD, CompteAD, PwdAD, OU, DC, AttributFiltre &#160; 'Paramétrage ServeurAD = &#34;127.0.0.1&#34; 'Machine hébergeant Active Directory CompteAD = &#34;DOMAINE\admin.ad&#34; 'Utilisateur autorisé à interroger Active Directory PwdAD = &#34;********&#34; 'Mot de passe de cet utilisateur OU = &#34;OU=Utilisateurs&#34; 'OU à [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #0000ff; font-weight: bold;">Function</span> RechercheUtilisateur<span style="color: #006600; font-weight:bold;">&#40;</span>utilisateur, attribut<span style="color: #006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color: #008000;">'Déclaration des variables</span>
<span style="color: #990099; font-weight: bold;">Dim</span> objConn, objRS
<span style="color: #990099; font-weight: bold;">Dim</span> Base, Filtre, Scope, Cmd
<span style="color: #990099; font-weight: bold;">Dim</span> ServeurAD, CompteAD, PwdAD, OU, DC, AttributFiltre
&nbsp;
<span style="color: #008000;">'Paramétrage</span>
ServeurAD <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;127.0.0.1&quot;</span>           <span style="color: #008000;">'Machine hébergeant Active Directory</span>
CompteAD <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;DOMAINE\admin.ad&quot;</span>     <span style="color: #008000;">'Utilisateur autorisé à interroger Active Directory</span>
PwdAD <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;********&quot;</span>                <span style="color: #008000;">'Mot de passe de cet utilisateur</span>
OU <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;OU=Utilisateurs&quot;</span>            <span style="color: #008000;">'OU à interroger</span>
DC <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;DC=domaine,DC=fr&quot;</span>           <span style="color: #008000;">'DC à interroger</span>
AttributFiltre <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;sAMAccountName&quot;</span> <span style="color: #008000;">'Filtre de recherche de l'utilisateur</span>
&nbsp;
<span style="color: #008000;">'Connexion à l'annuaire Active Directory</span>
<span style="color: #990099; font-weight: bold;">Set</span> objConn <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #330066;">CreateObject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;ADODB.Connection&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
objConn.<span style="color: #9900cc;">Provider</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;ADsDSOObject&quot;</span>
objConn.<span style="color: #330066;">Properties</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;User ID&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> CompteAD
objConn.<span style="color: #330066;">Properties</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Password&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> PwdAD
objConn.<span style="color: #330066;">Properties</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Encrypt Password&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">true</span>
objConn.<span style="color: #330066;">Open</span>
&nbsp;
<span style="color: #008000;">'Création de la requête</span>
<span style="color: #990099; font-weight: bold;">if</span> attribut<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;&quot;</span> <span style="color: #990099; font-weight: bold;">then</span>
        <span style="color: #008000;">'Permet la recherche simple de l'utilisateur (sans recherche d'attribut)</span>
	attribut <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;sAMAccountName&quot;</span>
<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
Base <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;&lt;LDAP://&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> ServeurAD <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;/&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> OU <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;,&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> DC <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;&gt;&quot;</span>
Filtre <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;(&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> AttributFiltre <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;=&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> utilisateur <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;)&quot;</span>
Scope <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;subtree&quot;</span>
Cmd <span style="color: #006600; font-weight: bold;">=</span> Base <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;;&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> Filtre <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;;&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> attribut <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;;&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> Scope
<span style="color: #990099; font-weight: bold;">set</span> objRS <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #990099; font-weight: bold;">Server</span>.<span style="color: #330066;">CreateObject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;ADODB.Recordset&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #990099; font-weight: bold;">set</span> objRS <span style="color: #006600; font-weight: bold;">=</span> objConn.<span style="color: #330066;">Execute</span><span style="color: #006600; font-weight:bold;">&#40;</span>Cmd<span style="color: #006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">If</span> objRS.<span style="color: #9900cc;">RecordCount</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">0</span> <span style="color: #990099; font-weight: bold;">Then</span>
        <span style="color: #008000;">'Aucun utilisateur trouvé</span>
	RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">false</span>
<span style="color: #990099; font-weight: bold;">Else</span>
	<span style="color: #990099; font-weight: bold;">if</span> IsNull<span style="color: #006600; font-weight:bold;">&#40;</span>objRS<span style="color: #006600; font-weight:bold;">&#40;</span>attribut<span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #990099; font-weight: bold;">then</span>
		<span style="color: #008000;">'Utilisateur trouvé, attribut recherché vide</span>
		RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;NULL&quot;</span>
	<span style="color: #990099; font-weight: bold;">else</span>
		<span style="color: #990099; font-weight: bold;">if</span> attribut<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;sAMAccountName&quot;</span> <span style="color: #990099; font-weight: bold;">then</span>
			<span style="color: #008000;">'Utilisateur trouvé, pas d'attribut recherché</span>
			RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">true</span>
		<span style="color: #990099; font-weight: bold;">else</span>
			<span style="color: #008000;">'Utilisateur trouvé, attribut recherché non-nul</span>
			RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> objRS<span style="color: #006600; font-weight:bold;">&#40;</span>attribut<span style="color: #006600; font-weight:bold;">&#41;</span>
		<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
	<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
&nbsp;
<span style="color: #008000;">'Fermeture du recordset et de la connexion</span>
objRS.<span style="color: #330066;">Close</span>
objConn.<span style="color: #330066;">Close</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Function</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>
<p>Exemple de recherche avec un attribut en paramètre :</p>
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;E-mail : &quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> RechercheUtilisateur<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;utilisateur.alpha&quot;</span>, <span style="color: #cc0000;">&quot;mail&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>
<p>Résultat :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">E-mail : utilisateur.alpha@domaine.fr</pre></div></div>
<p>Exemple de recherche &laquo;&nbsp;simple&nbsp;&raquo; :</p>
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;Utilisateur existant : &quot;</span>
<span style="color: #990099; font-weight: bold;">if</span> RechercheUtilisateur<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;utilisateur.alpha&quot;</span>,<span style="color: #cc0000;">&quot;&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight: bold;">=</span><span style="color: #0000ff; font-weight: bold;">true</span> <span style="color: #990099; font-weight: bold;">then</span>
	<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;oui&quot;</span>
<span style="color: #990099; font-weight: bold;">else</span>
	<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;non&quot;</span>
<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>
<p>Résultat :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Utilisateur existant : oui</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/07/24/fonction-asp-de-recherche-dun-utilisateur-active-directory/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Utiliser la date de la veille de façon simple, en batch</title>
		<link>http://blog.nicolas.pawlak.fr/2010/03/15/utiliser-la-date-de-la-veille-de-facon-simple-en-batch/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/03/15/utiliser-la-date-de-la-veille-de-facon-simple-en-batch/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 21:30:14 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Batch]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[variable]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[veille]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=667</guid>
		<description><![CDATA[&#171;&#160;Bah, il suffit juste de retirer 1 à la date du jour&#8230;&#160;&#187; Moui&#8230; mais non. Ce n&#8217;est pas en retirant 1 au 1er janvier que ça nous donnera la date du 31 décembre. Il existe sur Internet une multitude de solutions diverses, comme de gros scripts batch ou de simples scripts VBS. La solution que [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p></p>
<p align="center">&laquo;&nbsp;Bah, il suffit juste de retirer 1 à la date du jour&#8230;&nbsp;&raquo;</p>
</blockquote>
<p>Moui&#8230; mais non. Ce n&#8217;est pas en retirant 1 au 1<sup>er</sup> janvier que ça nous donnera la date du 31 décembre.</p>
<p>Il existe sur Internet une multitude de solutions diverses, comme de gros <a href="http://www.robvanderwoude.com/files/yesterday_nt.txt">scripts batch</a> ou de simples <a href="http://fixunix.com/ms-dos/345571-date-de-la-veille.html">scripts VBS</a>. La solution que j&#8217;utilise n&#8217;est peut-être pas la meilleure, mais a le mérite d&#8217;être simple à mettre en place, simple à comprendre, et facilement adaptable.</p>
<p>Le principe est le suivant : </p>
<p><strong>JOUR 0</strong></p>
<p>- enregistrer la date du jour dans un fichier X (contiendra la date du jour 0)</p>
<p><strong>JOUR 1</strong></p>
<p>- récupérer le contenu du fichier X (contient la date du jour 0)<br />
- remplacer le contenu du fichier X (contiendra la date du jour 1)</p>
<p><strong>JOUR 2</strong></p>
<p>- récupérer le contenu du fichier X (contient la date du jour 1)<br />
- remplacer le contenu du fichier X (contiendra la date du jour 2)</p>
<p>Et ainsi de suite. Les fins de semaine, jours fériés et chômés ne sont pas une difficulté tant que le fichier X est écrasé après chaque journée d&#8217;utilisation et non pas de manière automatique. Ainsi, dans le cas d&#8217;un traitement du lundi au vendredi, le fichier X contiendra le lundi la date du vendredi.</p>
<p>Passons à la pratique.</p>
<p><strong>Insertion de la date :</strong></p>
<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
echo <span style="color: #66cc66;">%</span>date<span style="color: #66cc66;">%</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">%</span>TEMP<span style="color: #66cc66;">%</span>\date_veille.txt
<span style="color: #800080;">exit</span></pre></div></div>
<p>A noter que vous pouvez adapter la date en fonction de vos envies : </p>
<p>- en retirant les <a href="http://fr.wikipedia.org/wiki/Barre_oblique">slashs</a> (<em>echo %date:/=%</em>),<br />
- en remplaçant les slashs par des tirets (<em>echo %date:/=-%</em>),<br />
- en changeant l&#8217;ordre pour année/mois/jour (<em>echo %date:~6%/%date:~3,2%/%date:~0,2%</em>)<br />
- &#8230; </p>
<p><strong>Récupération de la date :</strong></p>
<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
<span style="color: #800080;">for</span> <span style="color: #66cc66;">/</span>f <span style="color: #ff0000;">&quot;delims=&quot;</span> <span style="color: #66cc66;">%%</span>a <span style="color: #800080;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'type %TEMP%\date_veille.txt'</span><span style="color: #66cc66;">&#41;</span> do set date_veille=<span style="color: #66cc66;">%%</span>a
echo La date de la veille est <span style="color: #FF1010; font-weight: bold;">: %date_veille%</span>
echo.
<span style="color: #0000FF;">pause</span>
<span style="color: #800080;">exit</span></pre></div></div>
<p>Il existe toutefois une alternative : placer la date du jour dans une variable&#8230; et mettre le script en pause, via un énorme <a href="http://blog.nicolas.pawlak.fr/2010/01/06/une-commande-sleep-sous-windows-avec-les-moyens-du-bord/">sleep</a>, jusqu&#8217;à l&#8217;utilisation du lendemain. Mais avoir un script lancé pendant peut-être plus de 10 heures n&#8217;est pas forcément une bonne idée&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/03/15/utiliser-la-date-de-la-veille-de-facon-simple-en-batch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manipuler des noms de fichiers / chemins en batch</title>
		<link>http://blog.nicolas.pawlak.fr/2010/02/26/manipuler-des-noms-de-fichiers-chemins-en-batch/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/02/26/manipuler-des-noms-de-fichiers-chemins-en-batch/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 13:00:15 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Batch]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[chemin]]></category>
		<category><![CDATA[court]]></category>
		<category><![CDATA[dp0]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[fichier]]></category>
		<category><![CDATA[long]]></category>
		<category><![CDATA[nom]]></category>
		<category><![CDATA[nx0]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[variable]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=648</guid>
		<description><![CDATA[Comment faire pour exécuter des traitements dans un script .bat en fonction du nom du fichier ou de son chemin ? Il existe différentes variables prévues à cet effet, dont l&#8217;une était utilisée dans un article précédent. Prenons comme exemple un script test.bat situé dans C:\Documents and Settings\nicolas\. echo %~d0 Renvoie la lettre du lecteur [...]]]></description>
			<content:encoded><![CDATA[<p>Comment faire pour exécuter des traitements dans un script .bat en fonction du nom du fichier ou de son chemin ? Il existe différentes variables prévues à cet effet, dont l&#8217;une était utilisée dans un <a href="http://blog.nicolas.pawlak.fr/2010/01/30/reexecuter-un-script-bat-apres-redemarrage/">article précédent</a>.</p>
<p>Prenons comme exemple un script <strong>test.bat</strong> situé dans <strong>C:\Documents and Settings\nicolas\</strong>.</p>
<p><strong>echo %~d0</strong> </p>
<p>Renvoie la lettre du lecteur (<em>C:</em>).</p>
<p><strong>echo %~nx0</strong></p>
<p>Renvoie le nom du fichier et son extension (<em>test.bat</em>).</p>
<p><strong>echo %~x0</strong></p>
<p>Renvoie l&#8217;extension du fichier (<em>.bat</em>).</p>
<p><strong>echo %~f0</strong> </p>
<p>Renvoie le chemin complet au format long (<em>C:\Documents and Settings\nicolas\test.bat</em>).</p>
<p><strong>echo %~sf0</strong></p>
<p>Renvoie le chemin complet au format court (<em>C:\DOCUME~1\nicolas\test.bat</em>).</p>
<p><strong>echo %~p0</strong></p>
<p>Renvoie le chemin au format long sans le nom du fichier ni la lettre du lecteur (<em>\Documents and Settings\nicolas\</em>).</p>
<p><strong>echo %~dp0</strong></p>
<p>Renvoie le chemin au format long sans le nom du fichier (<em>C:\Documents and Settings\nicolas\</em>).</p>
<p><strong>echo %~sp0</strong></p>
<p>Renvoie le chemin au format court sans le nom du fichier ni la lettre du lecteur (<em>\DOCUME~1\nicolas\</em>).</p>
<p>Pour mettre en pratique, voici un script reprenant certaines de ces variables afin de tester le bon fonctionnement.</p>
<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
echo Le fichier se nomme   <span style="color: #FF1010; font-weight: bold;">: %~nx0</span>
echo Son extension est     <span style="color: #FF1010; font-weight: bold;">: %~x0</span>
echo Il est lance depuis   <span style="color: #FF1010; font-weight: bold;">: %~d0</span>
echo Le chemin complet est <span style="color: #FF1010; font-weight: bold;">: %~f0</span>
echo.
<span style="color: #0000FF;">pause</span>
<span style="color: #800080;">exit</span></pre></div></div>
<p>Et voici le résultat :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Le fichier se nomme   : test.bat
Son extension est     : .bat
Il est lance depuis   : C:
Le chemin complet est : C:\Documents and Settings\nicolas\test.bat
&nbsp;
Appuyez sur une touche pour continuer...</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/02/26/manipuler-des-noms-de-fichiers-chemins-en-batch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Réexécuter un script .bat après redémarrage</title>
		<link>http://blog.nicolas.pawlak.fr/2010/01/30/reexecuter-un-script-bat-apres-redemarrage/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/01/30/reexecuter-un-script-bat-apres-redemarrage/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 08:00:17 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Batch]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[nx]]></category>
		<category><![CDATA[nx0]]></category>
		<category><![CDATA[reboot]]></category>
		<category><![CDATA[redémarrage]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=563</guid>
		<description><![CDATA[Il arrive parfois que l&#8217;on doive redémarrer Windows après une installation ou une configuration du système. Lorsque cette installation ou configuration se fait automatiquement dans le cadre d&#8217;un fichier .bat, le redémarrage provoque évidemment l&#8217;interruption du script&#8230; qui doit donc être relancé au redémarrage, et qui doit détecter où en est l&#8217;installation. Pour éviter ce [...]]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://blog.nicolas.pawlak.fr/wp-content/uploads/2010/01/msdos.png"><img src="http://blog.nicolas.pawlak.fr/wp-content/uploads/2010/01/msdos.png" alt="" title="msdos" width="154" height="181" class="aligncenter size-full wp-image-643" /></a></p>
<p>Il arrive parfois que l&#8217;on doive redémarrer Windows après une installation ou une configuration du système. Lorsque cette installation ou configuration se fait automatiquement dans le cadre d&#8217;un fichier .bat, le redémarrage provoque évidemment l&#8217;interruption du script&#8230; qui doit donc être relancé au redémarrage, et qui doit détecter où en est l&#8217;installation. Pour éviter ce genre de problèmes, bien souvent, les commandes sont découpées en plusieurs fichiers .bat qui doivent être exécutés l&#8217;un après l&#8217;autre.</p>
<p>Il est cependant possible de gérer le redémarrage du système avec relance automatique du script au redémarrage et reprise de l&#8217;installation ou de la configuration à la bonne étape.</p>
<p>Techniquement, il faut faire appel à la clé suivante de la <a href="http://www.aidewindows.net/bdr1.php">base de registre</a> :</p>
<p><strong>[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce]</strong></p>
<p>Et y insérer une nouvelle valeur chaîne avec ces paramètres :</p>
<p><strong>Nom de la valeur :</strong> le nom de votre script, extension comprise (exemple : test.bat)<br />
<strong>Données de la valeur :</strong> le chemin complet vers votre script (exemple : C:\scripts\test.bat)</p>
<p>La clé RunOnce est en fait une variante de la clé Run (qui contient des exécutables lancés à chaque démarrage), à la différence près que RunOnce est vidée après chaque exécution.</p>
<p>Pour reprendre l&#8217;exécution à la bonne étape, avant le redémarrage, le plus simple est peut-être de créer un fichier placé dans le dossier temporaire de l&#8217;utilisateur (désigné par la <a href="http://www.commentcamarche.net/contents/systemes/variables-environnement.php3">variable d&#8217;environnement</a> %TEMP%). A chaque lancement, le script vérifie l&#8217;existence de ce fichier pour savoir quelle étape lancer. Une fois cette vérification faite, il faut que le script le supprime afin de ne pas se tromper d&#8217;étape à la prochaine exécution.</p>
<p>La principale difficulté est l&#8217;insertion dans la clé RunOnce. Récupérer le nom du fichier .bat, son chemin, et&#8230; &laquo;&nbsp;double antislasher&nbsp;&raquo; le chemin, c&#8217;est à dire remplacer : </p>
<p><strong>C:\scripts\test.bat </strong></p>
<p>par : </p>
<p><strong>C:\\scripts\\test.bat</strong></p>
<p>Pas si évident que cela&#8230; La solution :</p>
<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #ff0000;">&quot;%~nx0&quot;</span>=<span style="color: #ff0000;">&quot;%CD:\=\\%\\%~nx0&quot;</span></pre></div></div>
<p>Autant dire qu&#8217;on ne tombe pas dessus par hasard. Voici un exemple complet, que vous pouvez utiliser, modifier&#8230; au gré de vos envies (et de vos besoins !) :</p>
<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
&nbsp;
REM <span style="color: #66cc66;">--------------------------------------------------------------------</span>
REM
REM Reexecuter un script .bat apres redemarrage
REM
REM <span style="color: #66cc66;">--------------------------------------------------------------------</span>
&nbsp;
<span style="color: #800080;">if</span> exist <span style="color: #66cc66;">%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT <span style="color: #800080;">goto</span> etape2
<span style="color: #800080;">if</span> not exist <span style="color: #66cc66;">%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT <span style="color: #800080;">goto</span> etape1
&nbsp;
<span style="color: #FF1010; font-weight: bold;">:etape1</span>
&nbsp;
echo.
echo Reexecuter un script .bat apres redemarrage <span style="color: #66cc66;">-</span> Etape <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>
echo <span style="color: #66cc66;">--------------------------------------------------------------------</span>
echo.
echo Veuillez indiquer quelques informations pour tester le script...
echo.
set <span style="color: #66cc66;">/</span>p id=identifiant bidon <span style="color: #FF1010; font-weight: bold;">:</span>
set <span style="color: #66cc66;">/</span>p mdp=Mot de passe bidon <span style="color: #FF1010; font-weight: bold;">:</span>
echo.
echo <span style="color: #66cc66;">%</span>id<span style="color: #66cc66;">%&gt;%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT
echo <span style="color: #66cc66;">%</span>mdp<span style="color: #66cc66;">%&gt;&gt;%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT
&nbsp;
echo Modification de la base de registre...
echo.
&nbsp;
<span style="color: #66cc66;">&#40;</span>
<span style="color: #66cc66;">@</span>echo Windows Registry Editor <span style="color: #0000FF;">Version</span> <span style="color: #cc66cc;">5.00</span>
<span style="color: #66cc66;">@</span>echo<span style="color: #66cc66;">/</span>
<span style="color: #66cc66;">@</span>echo <span style="color: #66cc66;">&#91;</span>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">@</span>echo <span style="color: #ff0000;">&quot;%~nx0&quot;</span>=<span style="color: #ff0000;">&quot;%CD:\=\\%\\%~nx0&quot;</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&gt;%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT.reg
&nbsp;
regedit <span style="color: #66cc66;">/</span>s <span style="color: #66cc66;">%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT.reg
del <span style="color: #66cc66;">/</span>q <span style="color: #66cc66;">%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT.reg
&nbsp;
cls
echo.
echo Reexecuter un script .bat apres redemarrage <span style="color: #66cc66;">-</span> Etape <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>
echo <span style="color: #66cc66;">--------------------------------------------------------------------</span>
echo.
echo Les donnees ont ete enregistrees et seront affichees au redemarrage.
echo.
echo Testons a present le redemarrage du systeme
echo pour verifier que le script se relance bien.
echo.
&nbsp;
set <span style="color: #66cc66;">/</span>p choix=Voulez<span style="color: #66cc66;">-</span>vous redemarrer immediatement <span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">/</span>n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">?</span>
<span style="color: #800080;">if</span> <span style="color: #66cc66;">%</span>choix<span style="color: #66cc66;">%</span>==o <span style="color: #800080;">goto</span> oui
<span style="color: #800080;">if</span> <span style="color: #66cc66;">%</span>choix<span style="color: #66cc66;">%</span>==n <span style="color: #800080;">goto</span> non
&nbsp;
<span style="color: #FF1010; font-weight: bold;">:oui</span>
shutdown <span style="color: #66cc66;">-</span>r <span style="color: #66cc66;">-</span>t <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&amp;</span> <span style="color: #800080;">goto</span> fin
&nbsp;
<span style="color: #FF1010; font-weight: bold;">:non</span>
echo.
echo.
echo Votre systeme ne sera pas redemarre.
echo.
echo La suite au prochain demarrage de votre systeme.
echo.
<span style="color: #0000FF;">pause</span>
<span style="color: #800080;">exit</span>
&nbsp;
<span style="color: #FF1010; font-weight: bold;">:fin</span>
<span style="color: #800080;">exit</span>
&nbsp;
<span style="color: #FF1010; font-weight: bold;">:etape2</span>
&nbsp;
echo.
echo Reexecuter un script .bat apres redemarrage <span style="color: #66cc66;">-</span> Etape <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>
echo <span style="color: #66cc66;">--------------------------------------------------------------------</span>
echo.
&nbsp;
<span style="color: #800080;">for</span> <span style="color: #66cc66;">/</span>f <span style="color: #ff0000;">&quot;delims=&quot;</span> <span style="color: #66cc66;">%%</span>a <span style="color: #800080;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'type %TEMP%\TESTBAT'</span><span style="color: #66cc66;">&#41;</span> do <span style="color: #66cc66;">&#40;</span>
<span style="color: #800080;">if</span> not defined id set id=<span style="color: #66cc66;">%%</span>a
<span style="color: #66cc66;">&#41;</span>
<span style="color: #800080;">for</span> <span style="color: #66cc66;">/</span>f <span style="color: #ff0000;">&quot;delims=&quot;</span> <span style="color: #66cc66;">%%</span>a <span style="color: #800080;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'type %TEMP%\TESTBAT'</span><span style="color: #66cc66;">&#41;</span> do set mdp=<span style="color: #66cc66;">%%</span>a
&nbsp;
del <span style="color: #66cc66;">/</span>q <span style="color: #66cc66;">%</span>TEMP<span style="color: #66cc66;">%</span>\TESTBAT
&nbsp;
echo Affichage des donnees precedemment demandees...
echo.
echo Le login bidon est <span style="color: #FF1010; font-weight: bold;">: %id%</span>
echo Le mot de passe bidon est <span style="color: #FF1010; font-weight: bold;">: %mdp%</span>
echo.
echo Le test est termine. Si vous redemarrez, rien ne se lancera...
echo.
<span style="color: #0000FF;">pause</span>
<span style="color: #800080;">exit</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/01/30/reexecuter-un-script-bat-apres-redemarrage/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Pour les linuxiens qui soupirent quand ils tapent &#171;&#160;ls&#160;&#187; sur Windows&#8230;</title>
		<link>http://blog.nicolas.pawlak.fr/2010/01/15/pour-les-linuxiens-qui-soupirent-quand-ils-tapent-ls-sur-windows/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/01/15/pour-les-linuxiens-qui-soupirent-quand-ils-tapent-ls-sur-windows/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 09:00:49 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[dir]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ls]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[unxutils]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=438</guid>
		<description><![CDATA[Oui, j&#8217;en fais partie. Cela fait pourtant un bout de temps que j&#8217;utilise les deux systèmes, et mon vieux &#171;&#160;ls&#160;&#187; ne me lâche pas sur Windows. Je n&#8217;ai plus le réflexe du &#171;&#160;dir&#160;&#187; (à une époque, je n&#8217;avais pas encore vu la Lumière&#8230;). Première possibilité : Cygwin Cygwin est une collection d&#8217;outils Unix qui permet [...]]]></description>
			<content:encoded><![CDATA[<p>Oui, j&#8217;en fais partie. Cela fait pourtant un bout de temps que j&#8217;utilise les deux systèmes, et mon vieux &laquo;&nbsp;<em><a href="http://fr.wikipedia.org/wiki/Ls">ls</a></em>&nbsp;&raquo; ne me lâche pas sur Windows. Je n&#8217;ai plus le réflexe du &laquo;&nbsp;<em><a href="http://fr.wikipedia.org/wiki/Dir">dir</a></em>&nbsp;&raquo; (à une époque, je n&#8217;avais pas encore vu la Lumière&#8230;).</p>
<p><strong>Première possibilité : Cygwin</strong></p>
<p><a href="http://fr.wikipedia.org/wiki/Cygwin">Cygwin</a> est une collection d&#8217;outils <a href="http://fr.wikipedia.org/wiki/Unix">Unix</a> qui permet de retrouver sous Windows un environnement Unix (du moins pour la console). Vous trouverez des informations sur le téléchargement, l&#8217;installation et l&#8217;utilisation <a href="http://www.axul.org/Membres/fbarriere/folder.2005-09-19.2871215403/document.2005-09-23.8900311698/view">ici</a>&#8230; et sur de nombreux autres sites.</p>
<p>Attention, Cygwin a un côté &laquo;&nbsp;usine à gaz&nbsp;&raquo; qui fait qu&#8217;il ne correspondra peut-être pas à vos attentes&#8230;</p>
<p><strong>Seconde possibilité : UnxUtils</strong></p>
<p>Si Cygwin vous paraît trop lourd, trop complexe ou trop complet pour votre utilisation, UnxUtils est peut-être plus adapté à votre besoin. Il s&#8217;agit d&#8217;une archive regroupant une multitude de commandes Unix sous forme d&#8217;exécutables Windows. Parmi les plus intéressantes : ls, grep, tail, wget, dd, cut, wc, <a href="http://blog.nicolas.pawlak.fr/2010/01/06/une-commande-sleep-sous-windows-avec-les-moyens-du-bord/">sleep</a>&#8230;</p>
<p>Insérez les exécutables de votre choix dans C:\WINDOWS\system32 (ou dans le dossier de votre choix à condition de modifier la variable d&#8217;environnement <a href="http://www.wikituto.org/index.php/Variable_PATH_DOS">%PATH%</a>), et c&#8217;est parti !</p>
<p><a href="http://sourceforge.net/projects/unxutils/files/unxutils/current/UnxUtils.zip/download">Lien de téléchargement</a></p>
<p><strong>Troisième possibilité : à la main !</strong></p>
<p>Cette possibilité est faite pour parer au plus simple, pour les cas notamment où un ajout de fichier extérieur n&#8217;est pas forcément possible sur la machine.</p>
<p>Dans le dossier C:\WINDOWS\system32, créez un fichier nommé ls.bat et insérez-y le contenu suivant :</p>
<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">DIR</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">*</span></pre></div></div>
<p>Et voilà ! Court, mais efficace : la prochaine fois que vous taperez &laquo;&nbsp;<em><a href="http://fr.wikipedia.org/wiki/Ls">ls</a></em>&nbsp;&raquo; dans l&#8217;invite de commande, vous aurez le résultat d&#8217;un &laquo;&nbsp;<em><a href="http://fr.wikipedia.org/wiki/Dir">dir</a></em>&nbsp;&raquo; &#8230;</p>
<p>A noter toutefois que les paramètres Windows restent valables pour cette commande : vous pourrez faire par exemple un &laquo;&nbsp;<em>ls /w /p</em>&nbsp;&raquo; &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/01/15/pour-les-linuxiens-qui-soupirent-quand-ils-tapent-ls-sur-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

