<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Martin Zugec blog : Scripting</title><link>http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx</link><description>Tags: Scripting</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Create file with specified size</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/06/16/create-file-with-specified-size.aspx</link><pubDate>Mon, 16 Jun 2008 07:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1635552</guid><dc:creator>martin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1635552</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1635552</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/06/16/create-file-with-specified-size.aspx#comments</comments><description>&lt;p&gt;Yesterday I run into very strange problem with one of my friends - Echo. stopped working.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;In batch scripts, you use Echo to output something to screen - and of course you can redirect it to file.&lt;/p&gt;
&lt;p&gt;By using Echo. (mind the dot), you specify that you want to output empty line. So if you want to create empty file from batch, you can use Echo. &amp;gt; c:\Temp\Empty.txt&lt;/p&gt;
&lt;p&gt;Yesterday one script stopped working - Echo. was not working. It was working for everything else (including log files etc), just not for creating files in one folder. I have absolutely NO IDEA how that was possible (and if someone does, share any ideas, I am very curious about this one).&lt;/p&gt;
&lt;p&gt;I remembered of less known feature from FSUtil - FSUtil can create for you empty file with predefined size. And it worked:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;FSUtil File CreateNew C:\Temp\Empty.txt 0&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In my case I used it only as alternative method because Echo. failed, however it can be useful if you want to benchmark performance or do something similar. &lt;/p&gt;
&lt;p&gt;For example if I want to create 10 files with 10GB size, I would run following command:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;for /l %i IN (1,1,5) Do FSutil File CreateNew C:\Temp\PerfTest\Test%i 1073741824&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This would create 5 files with 10GB size. What I like about it that all files are created within miliseconds.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1635552" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>Lnk, shortcuts - real disaster??</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/29/lnk-shortcuts-real-disaster.aspx</link><pubDate>Thu, 29 May 2008 22:20:57 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1628947</guid><dc:creator>martin</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1628947</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1628947</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/29/lnk-shortcuts-real-disaster.aspx#comments</comments><description>&lt;p&gt;Maybe you noticed that one of my projects I would like to finish in summer is also offline shortcuts editor - and you probably think &amp;quot;why some editor when I can build shortcuts using Explorer?&amp;quot;... &lt;p&gt;Think twice - it&amp;#39;s not as easy as it looks like and you will be maybe surprised how many gotchas are there. &lt;p&gt;Problem with .lnk files is that they are WYSINWYG (What You See Is NOT What You Get). Windows is sometimes too &amp;quot;intelligent&amp;quot; - and it can be very, very annoying. &lt;p&gt; My blog is primarily focused on scripting, deployment and SBC - so I expect that my audience have also some experiences with this. And most people tried to create some shortcut and copy it somewhere else (you create shortcut to some drive letter on your PC and then copy it to desktop of all users for example). Problem is that together with shortcut you provide more information that you know - you provide also last successful resolution of that shortcut and you won&amp;#39;t see this information anywhere in properties of such shortcut. &lt;p&gt; Let me show you example. You map home drives of your users to H: drive. You want to have shortcut to H:\MyDocs on your desktop. So if you create shortcut to H:\MyDocs, then you just need to distribute it to all your workstations and its done. You open properties of this shortcut and you see that it points to H:\MyDocs, so it should work everywhere, right? &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;WRONG - don&amp;#39;t forget, Windows can be sometimes unpredictable ;) If you open properties of your .lnk file, you can see that it is (still) pointing to H:\MyDocs - however .lnk file also contains information that H:\MyDocs is in fact \\Servers\Administrator$\MyDocs and it will automatically open this folder even from different PC! Quite nasty, right?&lt;/p&gt; &lt;p&gt;And thats not all - try to remove that drive letter and open shortcut - because it remembers that location, it will automatically map H: to \\Servers\Administrator$\MyDocs&lt;/p&gt; &lt;p&gt;If you will try to map something else (\\Servers\Projects) to H: drive, Windows will surprise again - not only it will map that shortcut to different drive (X:), but it will also modify your shortcut so it is automatically changed from H:\MyDocs to X:\MyDocs... Which means that if you have 50 shortcuts pointing to H: drive, 1 accidental click can corrupt that shortcut for you.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;You can find many (well, not tons of, but still few of them exists) offline shortcuts editors, however most of them covers only situation I described above (and not of all them covers this). There are some bugs that are (as far as I know) not solved by any existing product - for example if you use variables to define your folders (for example %Programs% for D:\Programs), you WON&amp;#39;T be able to create such shortcut if variable is not defined. When you try to create it, C:\ prefix is automatically appended (so %Programs% is in fact pointing to C:\D:\Programs, which is invalid value). &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Well, this was just quick overview why I want to have offline editor where all such bugs will be fixed (btw I already have first version of code and it works correctly there, so it must be something in Explorer itself)... There are tons of other bugs&amp;nbsp; - I will try to spend some time testing different results and share results with you. I am now very sorry Microsoft didn&amp;#39;t implement something like &lt;a href="http://www.fileinfo.net/extension/xlnk" target="_blank"&gt;XLNK&lt;/a&gt; in Windows Vista :(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1628947" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Development/default.aspx">Development</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Projects/default.aspx">Projects</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>When is storing configuration in Windows directory good idea?</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/29/when-is-storing-configuration-in-windows-directory-good-idea.aspx</link><pubDate>Thu, 29 May 2008 09:30:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1628703</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1628703</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1628703</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/29/when-is-storing-configuration-in-windows-directory-good-idea.aspx#comments</comments><description>&lt;p&gt;Well, I know this is quite controversial, but in some cases (specially scripting frameworks) I think it is good idea to use Windows directory to store some settings\configuration...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Why that? Generally you can always divide such solutions to push or pull (and mixed of course) - that means that (if we talk about servers), sometimes you push some data to server (from your workstation\laptop) and sometimes you want server to retrieve information from some central storage\share.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Windows directory is suddenly only directory that is easily accessible both locally and remotely - from remote system you can use &lt;a&gt;\\Server\Admin$&lt;/a&gt; and from server itself you can simply use %WinDir% variable. &lt;/p&gt;
&lt;p&gt;I know most people would say that you can use &lt;a&gt;\\Server\C$&lt;/a&gt; and %SystemDrive%, but you never know if C: drive really exists (this is happening in SBC environment when you want to have client&amp;#39;s C: drive mapped at C letter). &lt;/p&gt;
&lt;p&gt;So for these reasons I like to use Windows directory - and then I make symlink\junction to some other location (so for example C:\Windows\CentralStorage\MyFramework --&amp;gt; C:\MyFramework). That way all required files are easily accessible for scripts (both push and pull) and also for administrators or people working with such environment.&lt;/p&gt;
&lt;p&gt;There are of course another ways how to achieve that - create new shares etc, however this method is most reliable and can be easily accessible&amp;nbsp;for all scripts\tools and also for all administrators. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1628703" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>SystemSherlockGUI - one package that rules them all ;)</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/26/systemsherlockgui-one-package-that-rules-them-all.aspx</link><pubDate>Mon, 26 May 2008 20:42:13 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1627630</guid><dc:creator>martin</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1627630</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1627630</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/26/systemsherlockgui-one-package-that-rules-them-all.aspx#comments</comments><description>&lt;p&gt;Good news everyone - I just received email from Roger (a.k.a. Kephyr) - he is author of brilliant SystemSherlock. He allowed me to include SystemSherlock in one package with my GUI - so now you can download&amp;nbsp; one package with both GUI and command line interface :)&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;To remind you, SystemSherlock is snapshoting utility (like Regshot), that can track changes on your filesystem or registry... &lt;/p&gt; &lt;p&gt;Snapshoting is sometimes (often) better than using ProcMon\RegMon\FileMon - you only see real changes, no reads etc... So I prefer snapshoting when I for example want to find where in registry are some changes hapenning.&lt;/p&gt; &lt;p&gt;Compared to RegShot, SystemSherlock is I think much better - you can compare unlimited dumps (not only 1st &amp;amp; 2nd snapshot) and I like GUI more ;)&lt;/p&gt; &lt;p&gt;Download and enjoy :) &lt;/p&gt; &lt;p&gt;&lt;iframe style="border-right:#dde5e9 1px solid;padding-right:0px;padding-left:0px;border-top:#dde5e9 1px solid;padding-bottom:0px;margin:3px;border-left:#dde5e9 1px solid;width:240px;padding-top:0px;border-bottom:#dde5e9 1px solid;height:66px;background-color:#ffffff;" src="http://cid-6f6355ee6be5160e.skydrive.live.com/embedrowdetail.aspx/MyProjects/SystemSherlockGUI.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt; &lt;p&gt;P.S.: If you have any feature requests or bugs to report, feel free to contact me, I would like to keep SystemSherlock alive&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1627630" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Development/default.aspx">Development</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>SystemSherlock - snapshot using GUI or CMD</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/17/systemsherlock-snapshot-using-gui-or-cmd.aspx</link><pubDate>Sat, 17 May 2008 21:32:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1623856</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1623856</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1623856</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/17/systemsherlock-snapshot-using-gui-or-cmd.aspx#comments</comments><description>&lt;p&gt;Recently I wrote about &lt;a href="http://msmvps.com/blogs/martinzugec/archive/2008/05/14/make-snapshots-of-filesystem-and-registry-using-command-line.aspx" target="_blank"&gt;SystemSherlock Lite&lt;/a&gt; - really nice snapshoting tool that supports command line... I also posted &lt;a href="http://msmvps.com/blogs/martinzugec/archive/2008/05/15/utility-to-display-logs-from-systemsherlock-lite.aspx" target="_blank"&gt;small utility&lt;/a&gt; for parsing log files.&lt;/p&gt;
&lt;p&gt;After that I started to heavily use SystemSherlock - and I must say that it is really really great utility. Problem is that usually you want to have command line AND GUI interface - and SystemSherlock is cmd only :(&lt;/p&gt;
&lt;p&gt;So I decided to create wrapper around it - and for me combination of GUI and SystemSherlock is much better snapshoting tool than RegShot or InstallRite... &lt;/p&gt;
&lt;p&gt;SystemSherlock GUI consists of 3 different tabs - one for creating snapshots, second for comparing snapshots and third for displaying log files in friendly structure.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Create snapshot&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Below is GUI used for taking snapshots:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msmvps.com/blogs/martinzugec/WindowsLiveWriter/SystemSherlockGUImyfavoritealternativeto_C6B6/image_2.png"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" border="0" alt="image" src="http://msmvps.com/blogs/martinzugec/WindowsLiveWriter/SystemSherlockGUImyfavoritealternativeto_C6B6/image_thumb.png" width="244" height="177" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;It allows you to create snapshot configuration, specify output file and also to include exclusion list if you want to ignore particular entries. This is configured snapshot for detecting HKCU and C:\Temp folder:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://msmvps.com/blogs/martinzugec/WindowsLiveWriter/SystemSherlockGUImyfavoritealternativeto_C6B6/image_4.png"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" border="0" alt="image" src="http://msmvps.com/blogs/martinzugec/WindowsLiveWriter/SystemSherlockGUImyfavoritealternativeto_C6B6/image_thumb_1.png" width="244" height="177" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;I tried to implement quite logical interface, so there are feature like auto-suggest or auto-repair of entries (for example HKLM is automatically translated HKEY_LOCAL_MACHINE)... Another feature is that entry type is automatically detected (you can see it in video - I don&amp;#39;t select whether entry is registry or filesystem, it is automatically filled):&lt;/p&gt;
&lt;p&gt;Update: Embedded video from Jing doesn&amp;#39;t work :( So click on following &lt;a class="" href="http://www.screencast.com/users/Soulin/folders/Jing/media/80b932d9-3be0-40c5-831a-5735065945be" target="_blank"&gt;link&lt;/a&gt;&amp;nbsp;instead).&lt;/p&gt;
&lt;p&gt;Once you specified what you want to monitor, just click on create button - dump is automatically created. Then do whatever you want - and just click on Create button again. One of SystemSherlock advantages is that it allows you to create as many dumps as you want - you can even compare current dump with one created months ago...&lt;/p&gt;
&lt;p&gt;When finished, move to Compare snapshots tab.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Compare snapshots&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Below is screenshot of Compare snapshots tab:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msmvps.com/blogs/martinzugec/WindowsLiveWriter/SystemSherlockGUImyfavoritealternativeto_C6B6/image_6.png"&gt;&lt;img style="BORDER-RIGHT:0px;BORDER-TOP:0px;BORDER-LEFT:0px;BORDER-BOTTOM:0px;" border="0" alt="image" src="http://msmvps.com/blogs/martinzugec/WindowsLiveWriter/SystemSherlockGUImyfavoritealternativeto_C6B6/image_thumb_2.png" width="244" height="177" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;It is divided to two parts - on left you can see source dumps and on right target dumps. Source dumps are the ones that were taken first -&amp;nbsp; this is VERY important to understand that source must be always older. &lt;/p&gt;
&lt;p&gt;System Sherlock Lite can report unexpected results if you are not aware of this behavior - if you will swap source and target (so target will be older file and source will be newer file), results will be opposite (for example if you deleted folder between snapshots, it will report that this folder was created etc.). &lt;/p&gt;
&lt;p&gt;For this reason I implemented some logic to processing. When you select any file on left, ONLY newer files then selected are displayed on right.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Parse logs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When you compare two dumps, differences between these two entries are automatically displayed in GUI.&lt;/p&gt;
&lt;p&gt;Current version should be already functional, but I am sure that there will be some issues - after all, this is really first version I just finished. If you encounter any problems or you have some features requests, feel free to post them in comments - if nothing, I will at least respond (but probably also implement such changes). &lt;/p&gt;
&lt;p&gt;Advantages compared to RegShot:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fully supports command line - can be scripted 
&lt;li&gt;Imho better GUI 
&lt;li&gt;Supports multiple dumps - not only comparison of 2 snapshots (easily review historical changes) 
&lt;li&gt;Exclusion list based on RegExes 
&lt;li&gt;GUI for reading log files&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;strong&gt;Download&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;iframe style="BORDER-RIGHT:#dde5e9 1px solid;PADDING-RIGHT:0px;PADDING-LEFT:0px;BORDER-TOP:#dde5e9 1px solid;PADDING-BOTTOM:0px;MARGIN:3px;BORDER-LEFT:#dde5e9 1px solid;WIDTH:240px;PADDING-TOP:0px;BORDER-BOTTOM:#dde5e9 1px solid;HEIGHT:66px;BACKGROUND-COLOR:#ffffff;" src="http://cid-6f6355ee6be5160e.skydrive.live.com/embedrowdetail.aspx/MyProjects/SystemSherlockGUI.exe" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1623856" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Deployment/default.aspx">Deployment</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Development/default.aspx">Development</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Projects/default.aspx">Projects</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Productivity/default.aspx">Productivity</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>Utility to display logs from SystemSherlock Lite</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/15/utility-to-display-logs-from-systemsherlock-lite.aspx</link><pubDate>Thu, 15 May 2008 10:29:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1622898</guid><dc:creator>martin</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1622898</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1622898</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/15/utility-to-display-logs-from-systemsherlock-lite.aspx#comments</comments><description>&lt;p&gt;As mentioned in my post about &lt;a class="" href="http://msmvps.com/blogs/martinzugec/archive/2008/05/14/make-snapshots-of-filesystem-and-registry-using-command-line.aspx" target="_blank"&gt;SystemSherlock Lite&lt;/a&gt;, I really love this tool after few days... Only problem I had is that it can take some time to realize what really happened - you need to read pretty big log files and you can spend precious time reading through temporary entries or documents and settings and miss one important entry saying that applications copied something to your System32 folder.&lt;/p&gt;
&lt;p&gt;I was playing with Sherlock yesterday and I spent lot of time parsing through log files generated by SystemSherlock. Then I spend 20 minutes writing some automated parser and I want to share with you ;)&lt;/p&gt;
&lt;p&gt;Usage is pretty simple - just click on Open log file, select your log file and output similar to following should appear:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msmvps.com/blogs/martinzugec/SystemSherlockReader.PNG"&gt;&lt;img src="http://msmvps.com/blogs/martinzugec/SystemSherlockReader.PNG" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I dont know what else to add - this utility is pretty simple, however can save your time ;) One more notice - log parse is able to handle also mixed logs (so if you have one log where you store different entries together with log output from SystemSherlock Lite, you can use it and it will only show entries from SystemSherlock Lite. &lt;/p&gt;
&lt;p&gt;Any comments, requests? Feel free to post comments...&lt;/p&gt;&lt;iframe style="BORDER-RIGHT:#dde5e9 1px solid;PADDING-RIGHT:0px;BORDER-TOP:#dde5e9 1px solid;PADDING-LEFT:0px;PADDING-BOTTOM:0px;MARGIN:3px;BORDER-LEFT:#dde5e9 1px solid;WIDTH:240px;PADDING-TOP:0px;BORDER-BOTTOM:#dde5e9 1px solid;HEIGHT:66px;BACKGROUND-COLOR:#ffffff;" src="http://cid-6f6355ee6be5160e.skydrive.live.com/embedrowdetail.aspx/MyProjects/SystemSherlockReader.exe" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1622898" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Development/default.aspx">Development</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Projects/default.aspx">Projects</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Productivity/default.aspx">Productivity</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>Another nasty Robocopy bug</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/14/another-nasty-robocopy-bug.aspx</link><pubDate>Wed, 14 May 2008 18:26:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1622601</guid><dc:creator>martin</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1622601</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1622601</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/14/another-nasty-robocopy-bug.aspx#comments</comments><description>&lt;p&gt;Recently&amp;nbsp;I wrote about &lt;a class="" title="but I found in Robocopy" href="http://msmvps.com/blogs/martinzugec/archive/2008/03/03/ugly-bug-in-robocopy-ignoring-security-on-file-level.aspx" target="_blank"&gt;bug I found in Robocopy&lt;/a&gt; - one of my favorite utilities... And today I found another one. &lt;/p&gt;
&lt;p&gt;I am using robocopy for synchronization - which is VERY important part of our framework (if nothing is synchronized, nothing can be executed). &lt;/p&gt;
&lt;p&gt;We use one folder for storing all log files. During migration to newer version of framework, I wanted to see only new entries for easier troubleshooting (many log files are not overwriting, but rather appending). So I renamed my Log folder to Log.Backup and tried to run synchronization... I run only backend part - that is part that is missing all checking, creation of required folders etc.&lt;/p&gt;
&lt;p&gt;To my surprise my synchronization failed - when I renamed Log.Backup to Log again it was working.&lt;/p&gt;
&lt;p&gt;Robocopy reported very strange error:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;ERROR : Invalid Parameter #4 : &amp;quot;/Log+:C:\Temp\Log\Robocopy.log&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I am using same syntax for many years, so I was really surprised. I double checked robocopy version to be sure that I didnt accidentaly replaced it with some 3.11 version - nope, I was using current version.&lt;/p&gt;
&lt;p&gt;Then I started to have that scary feeling that I know what is wrong - I tried to run it again, this time specifying folder that didnt exist - and I got same error as before. &lt;/p&gt;
&lt;p&gt;To summarize it - if Robocopy is not able to write to file, it reports &amp;quot;Invalid parameter&amp;quot;. If you specify that you want to store your settings in log file in folder that doesn`t exist - bang, &amp;quot;Invalid parameter&amp;quot;. &lt;/p&gt;
&lt;p&gt;Tested with newer and older versions of Robocopy - XP010 (Resource Kit), XP026 and XP027 (Vista). &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1622601" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category></item><item><title>Make snapshots of filesystem and registry using command line</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/14/make-snapshots-of-filesystem-and-registry-using-command-line.aspx</link><pubDate>Wed, 14 May 2008 12:43:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1622463</guid><dc:creator>martin</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1622463</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1622463</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/14/make-snapshots-of-filesystem-and-registry-using-command-line.aspx#comments</comments><description>&lt;p&gt;Some installers can be very mysterious - this suddenly applies for MSI packages, even using full logging, it is not easy to find out which registry keys or files were modified\deleted\added. If you have application that is using some custom installer, this can be hell...&lt;/p&gt;
&lt;p&gt;Colleague of mine came with really nice idea - what about using some tool like InstallRite or RegShot for monitoring all installations and reporting what was changed during that installation? From idea it is usually not far to implementation - you only need some tools to do it...&lt;/p&gt;
&lt;p&gt;I used utility called &lt;a class="" title="System Sherlock Lite" href="http://www.kephyr.com/systemsherlocklite/index.phtml" target="_blank"&gt;System Sherlock Lite&lt;/a&gt;&amp;nbsp;- it is very simple to use command line utility that can take snapshots from filesystem\registry and compare them. Of course it is freeware ;) It also supports exclusion list (using regexes), so you can easily configure it for your needs and ignore entries you are not interested in (usually log files or temporary folders). &lt;/p&gt;
&lt;p&gt;&amp;nbsp;So what I did is that I created 2 different scripts - StartMonitor and StopMonitor. &lt;/p&gt;
&lt;p&gt;StartMonitor is creating first snapshot.&lt;/p&gt;
&lt;p&gt;StopMonitor will create second snapshot, compare it with first snapshot and store differences in installation log file. Then it will delete both snapshots.&lt;/p&gt;
&lt;p&gt;This implementation is really easy, but is working really nice. Now I can easily monitor all installation I want automatically without any knowledge about installer being used or installation method. It allows me to easily debug anything from logon\logoff scripts to software installations...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1622463" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Deployment/default.aspx">Deployment</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Tips_2600_amp_3B00_Tricks/default.aspx">Tips&amp;amp;Tricks</category></item><item><title>New (simple) tool - SimpleScheduler</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/05/10/new-simple-tool-simplescheduler.aspx</link><pubDate>Sat, 10 May 2008 09:23:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1618762</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1618762</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1618762</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/05/10/new-simple-tool-simplescheduler.aspx#comments</comments><description>&lt;p&gt;I run into simple problem - I needed some (very basic) implementation of scheduled tasks. Scheduled tasks that are built-in to windows are not my best friend - problem is that (before Windows Vista, here they are completely different beast) it was not that easy to manage (automatically) scheduled tasks.&lt;/p&gt;
&lt;p&gt;For example if you wanted to reboot your servers by scheduled task and then enable them with another, you cannot be 100% sure that it will work. Problem is that if server is available when scheduled task should be executed, it will ignore it later on.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;For this reason I wrote really small script for myself and named it SimpleScheduler. It is using DateX, EchoX and Tee from Bill Stewart`s Shell Scripting Toolkit (which again I can only recommend).&lt;/p&gt;
&lt;p&gt;To enable it, just create one small scheduled task (give it any name you want, mine is SimpleSchedService) and configure it to run every few minutes (depends on what you want to run through it). I wrote about this concept few times ago and I still really like it, because it allows you to make very robust and reliable scripts (even if one run fails, another will usually finish its job). &lt;/p&gt;
&lt;p&gt;Once SimpleScheduler is running, that all you need to do on backend. All you need to do now is just create new jobs for it.&lt;/p&gt;
&lt;p&gt;Creating new jobs is pretty easy once you get used to it. Job always consists of 2 elements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;Job.cmd - script that will run. If you want to run anything else, to it from this script.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&amp;lt;DateID&amp;gt;.NextRun - this file identifies when you want to run scheduled task. &amp;lt;DateID&amp;gt; is date format used by DateX (with -t switch), so for example 950688458.NextRun.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;To create NextRun entries you must\should use DateX to generate ID when you want to run script. If you find this confusing, just post comment and I can add small script that will translate it automatically from you. &lt;/p&gt;
&lt;p&gt;By default all jobs that are not scheduled to run again are automatically deleted (you can change this in SimpleScheduler.ini configuration). Every job will automatically create log file (using Tee.exe from Bill).&lt;/p&gt;
&lt;p&gt;Main goal of this small script is to make more reliable scheduled tasks (ones that are immune to server reboot) and also to make easy scheduled tasks creation (all you need to do here is just copy folder to add new task or transfer it from one server to another).&lt;/p&gt;
&lt;p&gt;If you find it useful, please add some comments. If you want to add\change anything, please also write comments :)&lt;/p&gt;&lt;iframe style="BORDER-RIGHT:#dde5e9 1px solid;PADDING-RIGHT:0px;PADDING-LEFT:0px;BORDER-TOP:#dde5e9 1px solid;PADDING-BOTTOM:0px;MARGIN:3px;BORDER-LEFT:#dde5e9 1px solid;WIDTH:240px;PADDING-TOP:0px;BORDER-BOTTOM:#dde5e9 1px solid;HEIGHT:66px;BACKGROUND-COLOR:#ffffff;" src="http://cid-6f6355ee6be5160e.skydrive.live.com/embedrowdetail.aspx/MyProjects/SimpleScheduler.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1618762" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category></item><item><title>Useful tools for scripts</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/03/27/useful-tools-for-scripts.aspx</link><pubDate>Thu, 27 Mar 2008 10:09:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1556644</guid><dc:creator>martin</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1556644</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1556644</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/03/27/useful-tools-for-scripts.aspx#comments</comments><description>&lt;p&gt;One of my favorites are from SST (Shell Scripting Toolkit) from Bill Stewart (&lt;a href="http://www.westmesatech.com/"&gt;http://www.westmesatech.com/&lt;/a&gt;), but I dont understand why they are not really known in community. &lt;/p&gt;
&lt;p&gt;So I decided to post a little bit about them, maybe someone could be interested.&lt;/p&gt;
&lt;p&gt;Toolkit contains following utilities:&lt;/p&gt;
&lt;p&gt;CCase.exe&lt;br /&gt;ColorX.exe&lt;br /&gt;DateX.exe&lt;br /&gt;DriveX.exe&lt;br /&gt;EchoX.exe&lt;br /&gt;FInfo.exe&lt;br /&gt;IfX.exe&lt;br /&gt;LineX.exe&lt;br /&gt;S2V.EXE&lt;br /&gt;ShellEsc.exe&lt;br /&gt;SleepX.exe&lt;br /&gt;Str.exe&lt;br /&gt;Tee.exe&lt;br /&gt;TempName.exe&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CCase&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Change Case - allows you to change case using pipe, pretty simple and sometimes can be VERY useful. Just pipe output through ccase you you get results you want:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;C:\Temp\BillStewart&amp;gt;echo Testing cHAnGe Case | ccase -l&lt;br /&gt;testing change case&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;C:\Temp\BillStewart&amp;gt;echo Testing cHAnGe Case | ccase -u&lt;br /&gt;TESTING CHANGE CASE&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ColorX&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Do you want to use custom color scheme in your scripts? Or manipulate with it? ColorX allows you to detect current settings or change them. &lt;br /&gt;If you use -l switch, ColorX generates really nice overview of available colors, so you can quickly choose your combination. For example I like to have specific color of output to stress some facts (for example Success is light green, failure is red and important messages are orange), so you immediately see if there is anything wrong. Problem is that many people change default color, for example using red foreground (so all errors and warnings got lost). &lt;/p&gt;
&lt;p&gt;I can build simple workaround using ColorX:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;:: Store original settings&lt;br /&gt;For /f &amp;quot;UseBackQ tokens=*&amp;quot; %%c IN (`ColorX`) Do Set Settings.OriginalColor=%%c&lt;br /&gt;&lt;br /&gt;:: Change to MY settings (white frontground, black background)&lt;br /&gt;ColorX -c 0F&lt;br /&gt;&lt;br /&gt;:: Do something....&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;::Restore original settings&lt;br /&gt;ColorX -c %Settings.OriginalColor%&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DateX&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One of the biggest pains when handling with batches are date\time manipulation. Problem is that they are dependant on your regional settings and if you need to manipulate with multiple countries, scripts are getting VERY complex. Not to mention problems if you want to increase or decrease values&amp;nbsp;- my script for getting (universal) file creation time is 90 lines long. You will also probably (sooner or later) discover some cave-eats of batches - for example batch Set /a behavior. For example you want to store date one month ago in variable. It starts pretty simply - you just parse %Date% variable or use Date/t.&lt;/p&gt;
&lt;p&gt;Today is Thu 03/27/2008 - and you would like to run something like &lt;em&gt;Set /a 03 - 1&lt;/em&gt; (March - one month) and then have some check like&lt;em&gt; If&amp;nbsp;%Result% LSS 1 set /a %Result% + 12&lt;/em&gt; (that is probably easiest method how to handle with months). Still not see problem? If you would implement it today, you script will work for 5 months - and 1st of August it will stop working. Because we see &amp;quot;03&amp;quot;, Set /a automatically consider number is octet - and 08 doesnt exist in octat, so you will receive error:&lt;br /&gt;Invalid number.&amp;nbsp; Numeric constants are either decimal (17),&lt;br /&gt;hexadecimal (0x11), or octal (021).&lt;/p&gt;
&lt;p&gt;Well, to make long story short, just ignore batch functionality and use DateX instead. I am using DateX for two purposes - first one is for time comparison (here is it extremely useful) and also for predefining format I expect.&lt;/p&gt;
&lt;p&gt;Example of time comparison:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;For /f &amp;quot;usebackq tokens=*&amp;quot; %%x IN (`DateX -t`) Do Set Temp.Start=%%x&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;::Do something&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;For /f &amp;quot;usebackq tokens=*&amp;quot; %%x IN (`DateX -t`) Do Set Temp.End=%%x&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Set /a Temp.Duration=%Temp.End% - %Temp.Start%&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Echo Script was running for %Temp.Duration% seconds&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Of course changing it to minutes\hours etc is not problem at all.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DriveX&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Allows you to manipulate with drive and retrieve type of drive. Only problem I encountered (but there is probably nothing that can be done to fix this) is that it is not able to detect substed drives (mapped using Subst). Returned errorlevel identifies drive type - so 3 is fixed, 5 is CD-ROM etc.. &lt;/p&gt;
&lt;p&gt;It is most usefull if you want to process particular drive types. For example unmap all network drive command is pretty simple using DriveX:&lt;br /&gt;&lt;em&gt;For /f &amp;quot;UseBackQ Tokens=*&amp;quot; %%d IN (`DriveX -l 4`) Do Net Use %%d: /Delete&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EchoX.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;EchoX is probably my favorite utility and I use it with most of my scripts. What it allows you to do? Its pretty simple, you can change color of output (not WHOLE console window, only one line). Also I really like usage of escape characters that allows you to include line feed and return commands in one line.&lt;/p&gt;
&lt;p&gt;Consider scenario where something goes reaaaaally wrong - and you want to notify user. You want to display following message:&lt;br /&gt;&lt;br /&gt;:: Do something&lt;/p&gt;
&lt;p&gt;WARNING: Problem was detected when using script X.&lt;br /&gt;WARNING: Script will now abort.&lt;br /&gt;WARNING: Please contact your administrator&lt;br /&gt;&lt;br /&gt;:: Do some recovery&lt;/p&gt;
&lt;p&gt;Using &amp;nbsp;batches, you must write following &amp;quot;code&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;:: Do something&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Echo.&lt;br /&gt;Echo WARNING: Problem was detected when using script X.&lt;br /&gt;Echo WARNING: Script will now abort.&lt;br /&gt;Echo WARNING: Please contact your administrator&lt;br /&gt;Echo.&lt;br /&gt;&lt;br /&gt;:: Do some recovery&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Which is not bad, problem is that same color is used and it is really easy to miss such important information. With EchoX you use &lt;/p&gt;
&lt;p&gt;EchoX -c 0C &amp;quot;~nWARNING:Problem was detected when using script X.~nWARNING: Script will now abort.~nWARNING: Please contact your administrator~n&amp;quot;&lt;/p&gt;
&lt;p&gt;Of course you can split it to three lines. What is important is that this message is obviously error. It is really nice if you use it together with If Else:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;If /i #%Result%# EQU #OK# (&lt;br /&gt;EchoX -c 0A &amp;quot;Operation finished successfully&amp;quot;&lt;br /&gt;) Else (&lt;br /&gt;EchoX -c 0C &amp;quot;WARNING: Something wrong happened&amp;quot;&lt;br /&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That way you can change your batch script to appear&amp;nbsp;more like utilities. Highly recommended,&amp;nbsp;when I was searching for something&amp;nbsp;like this I found SST. You can find (very few) tools that&amp;nbsp;do the same, but all I tested had problems with buffer (text was truncated, sometimes corrupted etc)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;FInfo.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;FInfo allows you to dump some basic information about files. You specify file and you can get path only, file name etc. This functionality is not that important - you can achieve the same by implementing %~ (if you are interested, leave some comment and I can write how to use it). &lt;/p&gt;
&lt;p&gt;What is more interesting is option to get last modification time in same format as DateX (universal, no parsing needed). &lt;br /&gt;Also option to retrieve file size is really nice - output is obviously made for parsing (BTW Bill, if you read it, I cant stress enough how I appreciate parseable output ;)). &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IfX.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Not really useful today, because built-in If contains same functionality. Obviously it was build for 9x OSs, so dont expect anything really fancy here. It would be nice if it would contain features like IfX Starts With, IfX Ends With, IfX Contains etc...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;LineX.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Allows you to handle with output, generally Windows tails\head tools. Nice feature is that you can retrieve line n (so if your second line is always ::Created by, you can easily retrieve this). Usually you need to write some For /f with counter that tells you when to stop parsing - which is quite time consuming and not really reliable, so LineX can really help.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;S2V.EXE&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;MS-DOS utility to store output in variable. Replaced in NT by For /f, I never had chance to try it.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ShellEsc.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Could be really nice :( You can shellescaped any text - which is really great if you automate automation like I do ;) Problem is that ScellEsc was never really working for me - when it encountered empty line, it always crashed with message&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Runtime error 216 at $0040107F&lt;br /&gt;&amp;nbsp; $0040107F&lt;br /&gt;&amp;nbsp; $0006FFA8&lt;br /&gt;&amp;nbsp; $FFFFFFFF&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I completely forgot about this tool and I will try to write Bill if he still supports SST and if he could fix it - because I like to organize my code to make it easily readable.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SleepX.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Nice replacement of original Sleep. While original sleep allows you to specify time only, SleepX allows you to display message also and add option (and this is why I like it) to abort sleep by any key. One feature I am missing is that I would like SleepX to sleep forever if no timeout is specified and option to abort was enabled. I know I could use Sleep &amp;amp; Pause combination, but the idea is that you could allow people to define timeouts for different messages like this and use one code for all configurations.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Str.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Str allows in general two operations - first one is to change to uppercase\lowercase&amp;nbsp; and echo number of characters in string. For upper\lower case I prefer to use CCase, because it accepts pipe, but number of characters is sometimes very useful (especially if you want to do something where limited characters are allows). Second functionality is to detect string inside string and return starting position. I prefer using Str to handling with Find (you can detect if string exists by checking errorlevel), also because it allows me to easily detect if string STARTS with different string (which is sometimes quite important).&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tee.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Tee allows you to split output - so you can create log file that contains everything that is displayed to console. I like this concept, but prefer MTee to Tee because it contains more functionality.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TempName.exe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This tool could be quite useful, but I am still using script to do this:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;:GenerateCacheFolder&lt;br /&gt;Set Temp.ID=%Random%&lt;br /&gt;If Exist &amp;quot;%Folder.Root%\Cache\%Temp.ID%&amp;quot; Goto GenerateCacheFolder&lt;br /&gt;Set Temp.Cache=%FolderRoot%\Cache\%Temp.ID%&lt;br /&gt;MkDir &amp;quot;%Temp.Cache%&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1556644" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category></item><item><title>Ugly bug in Robocopy - ignoring security on file level</title><link>http://msmvps.com/blogs/martinzugec/archive/2008/03/03/ugly-bug-in-robocopy-ignoring-security-on-file-level.aspx</link><pubDate>Mon, 03 Mar 2008 20:34:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1532379</guid><dc:creator>martin</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1532379</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1532379</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2008/03/03/ugly-bug-in-robocopy-ignoring-security-on-file-level.aspx#comments</comments><description>&lt;p&gt;I really like RoboCopy (robust file copy) utility from Microsoft - if you dont know this tool (I would be surprised), it adds tons of features to standart Copy command - and probably the most useful is /MIR (mirror) that creates mirror of source folder.&lt;/p&gt;
&lt;p&gt;One of main benefits of mirror is that it is really fast and you can always use it to easily replicate different folders. Problem is that Mir is ignoring NTFS security.&lt;/p&gt;
&lt;p&gt;I know, I know, you can use /SEC - but you can still run into issues. Problem is that when using MIR switch, robocopy ignores ACL - so if you use RoboCopy Source Target /MIR /SEC, security settings are transfered - BUT if they are changed on source or target, these ACLs are not mirrored. This is only problem of files, not folders(!).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;This can be really annoying, currently you can use following as workaround:&lt;/p&gt;
&lt;p&gt;RoboCopy /Mir &amp;lt;Source&amp;gt; &amp;lt;Target&amp;gt;&lt;br /&gt;RoboCopy&amp;nbsp;/E /Copy:S /IS /IT &amp;lt;Source&amp;gt; &amp;lt;Target&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Second line will copy files again, but now with security...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Hope so Microsoft will fix this in next (if any) version of RoboCopy :( &lt;/p&gt;
&lt;p&gt;UPDATE: So, there are two newer versions than XP010 - version XP026 (that is part of Robocopy GUI) and XP027 (this is part of Windows Vista). Problem is that XP027 is not working under Windows XP\2003 (not tested, if someone have Vista, please test and let me know). Version XP026 is part of (not really useful - my opinion) Robocopy GUI. You can either install it and get Robocopy from System32... You can then use syntax RoboCopy &amp;lt;Source&amp;gt; &amp;lt;Target&amp;gt; /SecFix /xo /xn /xc /e /COPY:S&lt;br /&gt;This wont copy files, it will just reapply security settings.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;UPDATE2: Due to fact that it is not that easy to get Robocopy XP026 and you must install (quite ugly and useless) GUI to get it, I uploaded it to Microsoft SkyDrive:&lt;br /&gt;&lt;/p&gt;&lt;iframe style="BORDER-RIGHT:#dde5e9 1px solid;PADDING-RIGHT:0px;BORDER-TOP:#dde5e9 1px solid;PADDING-LEFT:0px;PADDING-BOTTOM:0px;MARGIN:3px;BORDER-LEFT:#dde5e9 1px solid;WIDTH:240px;PADDING-TOP:0px;BORDER-BOTTOM:#dde5e9 1px solid;HEIGHT:26px;BACKGROUND-COLOR:#ffffff;" src="http://cid-6f6355ee6be5160e.skydrive.live.com/embedrow.aspx/Tools/ROBOCOPY.EXE" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1532379" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Utilities/default.aspx">Utilities</category></item><item><title>Empty tokens in For /f?</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/11/13/empty-tokens-in-for-f.aspx</link><pubDate>Tue, 13 Nov 2007 10:38:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1305995</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=1305995</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=1305995</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/11/13/empty-tokens-in-for-f.aspx#comments</comments><description>&lt;p&gt;I received email with following question from Otto:&lt;/p&gt;
&lt;p&gt;I have file with delimiters, however not every token have values. For example following file:&lt;/p&gt;
&lt;p&gt;test1;test2;test3&lt;br /&gt;t1;;t3&lt;br /&gt;;te2;te3&lt;br /&gt;tes1;tes2; 
&lt;p&gt;If I try to use For /f to parse it (For /f &amp;quot;usebackq delims=; tokens=1,2,*&amp;quot; %%i IN (`Type Test.txt`) Do Echo a=%%i b=%%j c=%%k, following is output:&lt;/p&gt;
&lt;p&gt;a=test1 b=test2 c=test3&lt;br /&gt;a=t1 b=t3 c=&lt;br /&gt;a=te2 b=te3 c=&lt;br /&gt;a=tes1 b=tes2 c= 
&lt;p&gt;As you can see, For /f ignores empty tokens... So how to solve it? &lt;/p&gt;
&lt;p&gt;Only solution that came to my mind was to recommend using search&amp;amp;replace utility to replace these values first... However after some time I thought - &amp;quot;Hey, this is task ideal for regex replacement&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So I tried yesterday to write EmptyTokenParser.cmd that should be able to handle it (using SED from GnuWin32).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;@Echo off&lt;br /&gt;Set Int.File=%~1&lt;br /&gt;Set Int.Delimiter=%~2 
&lt;p&gt;type &amp;quot;%Int.File%&amp;quot; | sed s/&amp;quot;^%Int.Delimiter%&amp;quot;/&amp;quot;#empty#%Int.Delimiter%&amp;quot;/g;s/&amp;quot;%Int.Delimiter%%Int.Delimiter%&amp;quot;/&amp;quot;%Int.Delimiter%#Empty#%Int.Delimiter%&amp;quot;/g;s/&amp;quot;%Int.Delimiter%$&amp;quot;/&amp;quot;%Int.Delimiter%#Empty#/g 
&lt;p&gt;Usage is quite easy - EmptyTokenParser &amp;quot;Test.txt&amp;quot; &amp;quot;;&amp;quot; and result will appear like this:&lt;/p&gt;
&lt;p&gt;test1;test2;test3&lt;br /&gt;t1;#Empty#;t3&lt;br /&gt;#empty#;te2;te3&lt;br /&gt;tes1;tes2;#Empty# 
&lt;p&gt;&amp;nbsp;You must download SED to make it work. SED among many GREAT command line utilities can be found at &lt;a href="http://gnuwin32.sourceforge.net/"&gt;http://gnuwin32.sourceforge.net/&lt;/a&gt;. 
&lt;p&gt;So the final script:&lt;/p&gt;
&lt;p&gt;For /f &amp;quot;usebackq delims=; tokens=1,2,*&amp;quot; %%i IN (`EmptyTokenParser &amp;quot;Test.txt&amp;quot; &amp;quot;;&amp;quot;`) Do Echo a=%%i b=%%j c=%%k&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Output?&lt;/p&gt;
&lt;p&gt;a=test1 b=test2 c=test3&lt;br /&gt;a=t1 b=#Empty# c=t3&lt;br /&gt;a=#empty# b=te2 c=te3&lt;br /&gt;a=tes1 b=tes2 c=#Empty# 
&lt;p&gt;P.S.: Do you also use your blogs to write reminders? ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1305995" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>HookApplication - some real-life examples</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/03/01/hookapplication-some-real-life-examples.aspx</link><pubDate>Thu, 01 Mar 2007 12:59:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:629415</guid><dc:creator>martin</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=629415</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=629415</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/03/01/hookapplication-some-real-life-examples.aspx#comments</comments><description>&lt;P&gt;I still dont think its time for public release, however I just wanted to share with you some different situations where I liked to use HookApplication...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;For most of this actions I needed to write some plugins - I decided to keep HookApplication as simple as possible to have it as error-prone as possible. &lt;/P&gt;
&lt;P&gt;First I tried to replace processes - I replaced Task Manager with Process Explorer and after some time also Notepad with Crimson Editor...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Right now I am thinking about installing Maxthon 2.0 and if I found it useful, I will replace Internet Explorer with it. &lt;/P&gt;
&lt;P&gt;This was quite interesting, however nothing really special. For example Process Explorer supports replacement of Task Manager in its options... &lt;/P&gt;
&lt;P&gt;Then I found out I can use HookApplication to solve one of my problems I got right now - locking processes with passwords.&lt;/P&gt;
&lt;P&gt;Why do I need this? I am citrix administrator and if I am debugging something, I would like to be able to run task manager - however I want to prevent users to do the same. Problem is that I often&amp;nbsp;need to run task manager under THEIR account, not mine. So I wrote small stupid plugin, that will pop-up password message box when you try to run specific process and if you dont know password. &lt;/P&gt;
&lt;P&gt;I got it working with task manager - and it works great :)&lt;/P&gt;
&lt;P&gt;So, I was thinking what were other ways how users were "hacking" citrix boxes usually - one of them is somehow (taskmgr, word etc - there are many ways) running cmd and then you can do almost what you want. &lt;/P&gt;
&lt;P&gt;Created new plugin - if process is launched without any parameters (or vice versa),&amp;nbsp;pop-up input box with password&amp;nbsp;:) That means that scripts will run (cmd + parameters), however without password you are not able to use it...&lt;/P&gt;
&lt;P&gt;Another usage was related to allowing only one instance running - I have few applications that doesnt always exit correctly (GUI not visible, however application still running) and some of them are extremely stupid when handling such situation (Miranda wont show GUI for example...). New plugin -&amp;nbsp; check instances - if more than x running, do something (for some processes just popup message box, for some kill current process, for some kill rest of processes....). Quite simple, however it helped me a lot, since this I havent experienced any problems :)&lt;/P&gt;
&lt;P&gt;Then I have some network related applications - for example I am killing all processes that are "calling home" before running VPN and then I am running them again or I am checking if NIC is enabled when trying to connect through EDGE (sometimes it fails on Unknown error if card is disabled)... &lt;/P&gt;
&lt;P&gt;Another useful scenario for me was using Hook Application together with AutoIt scripts - sometimes you just want to automate something, however its not as simple as it looks like - you can end up with never-ending script (which is quite stupid) that will wait under condition appears (window title appears for example) or you can run your program using script (which is nothing for me as sometimes run programs using Start Menu, Launchy or shortcuts ;)). So with hook application I just assigned few AutoIT scripts with related processes and viola - its working exactly as I was expected :)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Also I got some processes that I sometimes accidentaly close, but I want to keep them running all the time - for example GUI for my scripts. So I created entry that will run the command again when it is closed and it is working :) &lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=629415" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Other/default.aspx">Other</category></item><item><title>Introduction to batch services</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/02/12/introduction-to-batch-services.aspx</link><pubDate>Mon, 12 Feb 2007 09:28:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:570062</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=570062</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=570062</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/02/12/introduction-to-batch-services.aspx#comments</comments><description>&amp;nbsp; 
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;This blog post is going to be interesting mostly for people that got already a lot of experiences with batch scripting.&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;I am going to talk about quite interesting stuff I call batch services - I love this technology and it saved me and helped me many times in all my previous projects.&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;Batch service is in fact quite simple - it is just batch, that got actions linked to different folders and it is running periodically. &lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;In my current job, we are using batch services for automatic rebooting of servers and for sending mails, however it was extremely useful for deployment because you were able to do a lot of stuff with very simple scripts. &lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;Consider scenario where you want to allow your technicians to unlock some accounts for example without giving them permissions. &lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;You write script called UnlockAccountEngine.cmd. This script will consist of following lines:&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;For /f "usebackq delims=. tokens=1,*" %%i IN (`Dir /s /b "&lt;A&gt;\\server\UnlockAccounts$\Account.*"`&lt;/A&gt;) Do (&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;"&gt;Echo %Date%;%Time%;%UserDomain%;%%j&amp;gt;&amp;gt;"&lt;A&gt;\\Server\UnlockAccounts$\Unlock.log&lt;/A&gt;"&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;"&gt;Net User %UseDomain%\%%j /Domain /Active:Yes&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;)&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;Extremely simple, right? What it means is that it will unlock every account when file Account.UserName is available. For example if I would like to unlock my account, I will just create file Account.Mzugec.&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;Now we will create client script call UnlockAccount.cmd&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;This file contains following lines:&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;@Echo off&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;Set /p Int.AccountName=Please specify account name which you would like to unlock:&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;If Exist &lt;A&gt;\\Server\UnlockAccounts$\Account.%Int.AccountName%&lt;/A&gt; (&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;"&gt;Echo WARNING: Request to unlock this account was already sent&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;) Else (&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;"&gt;Echo.&amp;gt;&lt;A&gt;\\Server\UnlockAccounts$\Account.%Int.AccountName%&lt;/A&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;)&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;If Exist &lt;A&gt;\\Server\UnlockAccounts$\Account.%Int.AccountName%&lt;/A&gt; (&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;"&gt;Echo Request to unlock account %Int.AccountName% is registered, please wait few minutes and try it again&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;) Else (&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;"&gt;Echo WARNING:&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Request to unlock account %Int.AccountName%&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;was not created, please contact your IT support&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;)&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;This script is really simple, you just specify account name and then you will see if request (file) was successfully created or not.&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;Now we need to perform just last step - &lt;STRONG&gt;create scheduled task called UnlockAccountEngine and schedule it to run every 3 minutes (!).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;What will happen? Every 3 minutes script UnlockAccountEngine will run and it will unlock any account that is locked. Extremely simple, but also extremely useful in fact :) &lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;There are many advantages - this script wont hang, you don’t need to delegate any privileges, you can use scripts, web pages, even emails to generate such files (to do something, you just create one file, can it be simplier?)… &lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE:11pt;MARGIN:0in;FONT-FAMILY:Calibri;"&gt;There are many different scenarios what you can do with batch engines. For example if you are deployment guy, you can let users "request" software based on their needs, or you can run some program on remote machine (VNC server?) and many many other options. &lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=570062" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>How to detect if folder exist (and ignore file with same name ;))</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/01/30/how-to-detect-if-folder-exist-and-ignore-file-with-same-name.aspx</link><pubDate>Tue, 30 Jan 2007 08:50:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:528058</guid><dc:creator>martin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=528058</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=528058</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/01/30/how-to-detect-if-folder-exist-and-ignore-file-with-same-name.aspx#comments</comments><description>&lt;P&gt;Today I experienced really annoying bug with one of my scripts. It is checking if one folder (in quite complex structure) exists(&lt;EM&gt;If Exist Folder...&lt;/EM&gt;), if it does, it perfoms some actions and send few mails. However after some time it started to behave strange - it was sending sometimes mail when folder was definitely not there etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;It didnt take me long time to discover what was the problem - another team was using file without extension with same name as my folder :) So I rewrote today this script to detect ONLY folder and ignore files with same name. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;How to do it? Its quite simle&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;If Exist Folder\nul.ext Send-Mail&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For example &lt;EM&gt;If Exit C:\Temp\test\nul.ext&lt;/EM&gt; will be True if folder test exists, however not if file test exists.&lt;/P&gt;
&lt;P&gt;You just need to be very careful - Windows doesnt allow you to have folder and file with same name in same folder:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;C:\Temp&amp;gt;mkdir Test&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;C:\Temp&amp;gt;Echo.&amp;gt;test&lt;BR&gt;Access is denied.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;C:\Temp&amp;gt;rmdir Test&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;C:\Temp&amp;gt;Echo.&amp;gt;test&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;C:\Temp&amp;gt;mkdir Test&lt;BR&gt;A subdirectory or file Test already exists.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;C:\Temp&amp;gt;&lt;/EM&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=528058" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>How to dial using default RAS connection</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/01/29/how-to-dial-using-default-ras-connection.aspx</link><pubDate>Mon, 29 Jan 2007 21:14:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:527454</guid><dc:creator>martin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=527454</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=527454</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/01/29/how-to-dial-using-default-ras-connection.aspx#comments</comments><description>&lt;P&gt;TuxExplorer send me question how to dial connection using default RAS connection - I wrote small script (two liner) to do that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;For /f "usebackq tokens=1-3" %%i IN (`reg query "HKCU\Software\Microsoft\RAS AutoDial\Default" /v DefaultInternet ^| find /i "REG_SZ"`) Do If /i #%%j# EQU #REG_SZ# Set Int.DefaultRASConnection=%%k&lt;BR&gt;&lt;BR&gt;If Defined Int.DefaultRASConnection Start RasPhone -d %Int.DefaultRASConnection%&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;It should work, I just connected using this script :)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Martin&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=527454" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>How to specify timeout for script?</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/01/29/how-to-specify-timeout-for-script.aspx</link><pubDate>Mon, 29 Jan 2007 17:01:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:527221</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=527221</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=527221</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/01/29/how-to-specify-timeout-for-script.aspx#comments</comments><description>&lt;P&gt;Maybe you run into this issue before - you want to run some script/utility (for example query user), but you know that it hangs sometimes and you would like to have some kind of timeout utility. There is way how to handle this in batch scripts using two concurent scripts:&lt;/P&gt;
&lt;P&gt;Create three scripts, for example Scripts.cmd, Pause.cmd and Detection.cmd&lt;/P&gt;
&lt;P&gt;Content of Script.cmd is&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Set Int.Command=%~1&lt;BR&gt;Set Int.Pause=%~2&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Set Int.PauseTitle=%Random%PauseScript&lt;BR&gt;Set Int.DetectionTitle=%Random%DetectionScript&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Start /Min Cmd /c Detection.cmd&lt;BR&gt;Start cmd /c exit /b 1&lt;BR&gt;Start /Min /Wait cmd /c Pause.cmd&lt;BR&gt;If %ErrorLevel% EQU 0 (&lt;BR&gt;&amp;nbsp;Echo Failure&lt;BR&gt;) Else (&lt;BR&gt;&amp;nbsp;Echo Success&lt;BR&gt;)&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Content of Pause.cmd is&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Title %Int.PauseTitle%&lt;BR&gt;Sleep %Int.Pause%&lt;BR&gt;Taskkill /f /t /fi "WINDOWTITLE eq %Int.DetectionTitle%"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Content of Detection.cmd is &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Title %Int.DetectionTitle%&lt;BR&gt;%Int.Command%&lt;BR&gt;Taskkill /f /t /fi "WINDOWTITLE eq %Int.PauseTitle%"&lt;BR&gt;Exit /b 0&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Then call Script.cmd with two arguments, command to perform and timeout. For example Script.cmd "pause" "10". &lt;/P&gt;
&lt;P&gt;It will try to execute command "Pause", and if it took more then 10 seconds, it will kill this process and report it using errorlevel. &lt;/P&gt;
&lt;P&gt;Quite simple, however functional. This way it is also fast, because if your scripts finished faster, it will automatically remove Sleep subroutine that will hold main script execution. &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;I am using this procedure right now to detect hanging sessions on servers - and it turns out to be really simple and functional, so I wanted to share :)&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=527221" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Security issue with PowerShell</title><link>http://msmvps.com/blogs/martinzugec/archive/2007/01/25/security-issue-with-powershell.aspx</link><pubDate>Thu, 25 Jan 2007 08:47:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:518156</guid><dc:creator>martin</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=518156</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=518156</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2007/01/25/security-issue-with-powershell.aspx#comments</comments><description>&lt;p&gt;Hi guys, &lt;/p&gt;
&lt;p&gt;&amp;nbsp;after (too) long time I can finally return to Powershell (I spend few months creating batch framework to manage citrix servers, right now it is about 980 scripts). &lt;/p&gt;
&lt;p&gt;I was playing with Get-Credential:&lt;/p&gt;
&lt;p&gt;$Operator = get-credential&lt;/p&gt;
&lt;p&gt;I provided my username/password. If I have a look at object, I can see Password property and GetPassword() method. I tried this, Output is in System.Security.SecureString.&lt;/p&gt;
&lt;p&gt;I was just thinking how PowerShell is handling explicit authentication, so I had a look at available properties and methods - GetNetworkCredential grab my eye, so I tried it. And I was really surprised by output:&lt;/p&gt;
&lt;p&gt;mzugec&amp;gt;$operator.GetNetworkCredential()&lt;/p&gt;
&lt;p&gt;UserName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Password&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Domain&lt;br /&gt;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------&lt;br /&gt;mzugec&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YouPwdInPlainText&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyDomain&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Replace YouPwdInPlainText with your actual password! So be aware, if you are using get-credentials, it is very easy to retrieve your actual password!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=518156" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Monad/default.aspx">Monad</category><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Security/default.aspx">Security</category></item><item><title>Using functions in cmd (advanced scripting no.3)</title><link>http://msmvps.com/blogs/martinzugec/archive/2006/03/31/88658.aspx</link><pubDate>Fri, 31 Mar 2006 08:22:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:88658</guid><dc:creator>martin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=88658</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=88658</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2006/03/31/88658.aspx#comments</comments><description>&lt;P&gt;Comment from Alun Jones (thx!)&amp;nbsp;reminds me I forget to mention "functions" in batches! We were talking about script block, which are great if you combine them with call... Lets have a look what I have in my mind:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Echo Beginning...&lt;BR&gt;...&lt;BR&gt;...&lt;BR&gt;Call :CheckForUserName %UserName%&lt;/EM&gt;&lt;EM&gt;&lt;BR&gt;...&lt;BR&gt;...&lt;BR&gt;Echo End...&lt;/EM&gt;&lt;EM&gt;&lt;BR&gt;Goto EndOfScript&lt;BR&gt;&lt;BR&gt;:: Subroutines&lt;BR&gt;:CheckForUserName&lt;BR&gt;Net User %1 /Domain &amp;gt; nul&lt;BR&gt;If %ErrorLevel% NEQ 0 (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Echo User doesnt exist&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Goto EndOfScript&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;) Else (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Echo User exist&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;:EndOfScript&lt;BR&gt;&lt;BR&gt;&lt;/EM&gt;If you use it this way, you can see that it will execute CheckForUserName with parametere username and then it will return back (where Call was used), which can be extremely usefull sometimes. &lt;/P&gt;
&lt;P&gt;However sometimes you need to end function (for example if error is encountered). Many people are asking me why I am always using EndOfScript when I can simply use Goto :EOF command - the reason is that if Goto :EOF is used inside this function, it WONT just to end of script - it will simply jump to end of function!&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=88658" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Script blocks in CMD (advanced scripting no.2)</title><link>http://msmvps.com/blogs/martinzugec/archive/2006/03/30/88516.aspx</link><pubDate>Thu, 30 Mar 2006 12:39:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:88516</guid><dc:creator>martin</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/rsscomments.aspx?PostID=88516</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/martinzugec/commentapi.aspx?PostID=88516</wfw:comment><comments>http://msmvps.com/blogs/martinzugec/archive/2006/03/30/88516.aspx#comments</comments><description>&lt;P&gt;Well, I know I talked about this few times, but I decided to write more comprehensive article about this (this will follow previous about delayed expansion). &lt;/P&gt;
&lt;P&gt;Many people think batches are stupid - I dont agree, I think you can do miracles with batches. &lt;/P&gt;
&lt;P&gt;One of not really often used features are script block - I mean commands that are on more than one line. You can often see this:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If %Errorlevel% NEQ 0 Echo Error %ErrorLevel% occured!&lt;BR&gt;&lt;EM&gt;If %Errorlevel% NEQ 0 FixError.cmd %ErrorLevel%&lt;BR&gt;&lt;EM&gt;If %Errorlevel% NEQ 0 Goto EndOfScript&lt;/EM&gt;&lt;/EM&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You can write this in more intelligent way:&lt;EM&gt;If %Errorlevel% NEQ 0 (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Echo Error %ErrorLevel% occured!&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FixError.cmd %ErrorLevel%&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Goto EndOfScript&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;And this is script block. You can use them either with If command or For command... And you can have many nested script blocks... For example this:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;If %ErrorLevel% NEQ 0 (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;For /f "usebackq delims== tokens=1-2" %%i IN (`Set Error.`) Do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Echo Error %%j occured&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Goto EndOfScript&lt;BR&gt;)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Of course this is just example - you can make much MORE complex script blocks, for example some of mine are about 50 lines long (and when they are running, they create like 300 lines of code). When you get familiar with script block, you wont use common GoTo structure anymore - there is no need to. &lt;/P&gt;
&lt;P&gt;But there is also one disadvantage - you must be advanced script write, because the script block is evaluated at beggining, so if you have some error, it is sometimes really hard to find out whats wrong. &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=88516" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/martinzugec/archive/tags/Scripting/default.aspx">Scripting</category></item></channel></rss>