Archive for the ‘Batch-Files’ Category
Posted by jpluimers on 2012/10/08
Most console applications return 0 (zero) as success.
But sometimes there are multiple success result codes, and the success depends on what you want to do with them.
One example is RoboCopy.
The zero result code means that nothing happened: no error occurred and nothing was copied, because there was no need to.
But for most RoboCopy scenario’s result code 1 (one) is also success. It means that no error occurred and that one ore more files were copied.
In fact the RoboCopy result codes form a bitmap explained on ss64.com.
Most RoboCopy use cases will have [0,1] as the set off success result codes.
–jeroen
via: Robocopy Exit Codes.
Posted in Batch-Files, Development, Power User, RoboCopy, Scripting, Software Development, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | 3 Comments »
Posted by jpluimers on 2012/08/15
A few weeks ago, Bill Karwin did a must watch webinar on the prevention SQL Injection titled “SQL Injection Myths and Fallacies“.
Bill Karwin (twitter, new blog, old blog, Amazon) is famous for much work in the SQL database community, including InterBase/Firebird, mySQL, Oracle and many more.
He also:
Anyway, his webinar is awesome. Be sure to get the slides, watch the replay, and read the questions follow up.
Watching it you’ll get a better understanding of defending against SQL injection.
A few very valuable points he made: Read the rest of this entry »
Posted in .NET, .NET 3.5, .NET 4.5, .NET ORM, ASP.NET, Batch-Files, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Cloud Development, COBOL, CommandLine, Database Development, Delphi, Delphi for PHP, Delphi x64, Delphi XE2, Development, EF Entity Framework, F#, Firebird, FireMonkey, History, InterBase, iSeries, Java, JavaScript/ECMAScript, Jet OLE DB, LINQ, LLBLGen, MEF, Microsoft Surface, Mobile Development, PHP, PowerShell, Prism, Scripting, SharePoint, SilverLight, Software Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7, VB.NET, VBS, Visual Studio 11, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools, Web Development, Windows Azure, WinForms, WPF, XAML, xCode/Mac/iPad/iPhone/iOS/cocoa | 1 Comment »
Posted by jpluimers on 2012/05/15
When in a DTAP environment, you cannot always have complete clean boundaries. Issues in production don’t reproduce in acceptance, you cannot develop in production, etc.
So sometimes you have to simulate or connect to Test or Acceptance Database Servers from a Develop workstation.
There it can get hairy to keep track of which applications connect to which database server.
That’s where the below batch file comes in handy: it scans your systems on connections to common TCP ports used by SQL server, then for each connection give you some process details (or – if you add a commandline parameter – all details that TLINK can get).
The batch file uses the built in tools tasklist, netstat, find and sc (the latter to show information on the local running SQL Services).
It also uses TLIST, which can be a bit awkward to get.
Read the rest of this entry »
Posted in .NET, Batch-Files, CSV, Database Development, Development, Scripting, Software Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | Leave a Comment »
Posted by jpluimers on 2012/04/26
Some very interesting tips from game development that apply juts as well to general software development.
On code health:
Now I always try to dig right down to the root cause of a bug, even if a simple, and seemingly safe, patch is available. I want my code to be healthy. If you go to the doctor and tell him “it hurts when I do this,” then you expect him to find out why it hurts, and to fix that.
Though tools like SourceMonitor can help you track your code health, the best tool is between your ears.
–jeroen
via: Dodgy Coder: Coding tricks of game developers.
Posted in .NET, Batch-Files, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Delphi x64, Delphi XE2, Development, JavaScript/ECMAScript, PHP, PowerShell, Scripting, Software Development | 1 Comment »
Posted by jpluimers on 2012/04/17
If you followed my blog, you probably already guessed that I’m assisting a client to prepare for a big SQL Server 2000 to SQL Server 2008 R2 migration. When not, you know now :)
I’m a fan of commandline, tools, and preconfigured settings. Which means that I’m in the midst of reconfiguring all my shortcuts to SQL Server 2000 tools to SQL Server 2008 equivalents.
When inspecting and changing LNK shortcut files, two tools are important:
- dumplnk: dumps a shortcut lnk file from the commandline
- shurtcut: creates a shortcut lnk file from the commandline
One of tools I many shortcuts for is the ISQLW aka SQL Query Analyzer, which I use far more than the SQL Server Enterprise Manager (more on SSEM in a future post).
Depending on the mode of authentication you use to connect to your SQL Server, there basically are two forms of shortcuts:
- SQL Server Authentication (using SQL Server username and password):
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe" /S"servername[\instancename]" /U"username" /P"password"
- Windows Authentication (using the credentials of the currently logged in windows user):
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe" /S"servername[\instancename]" /E
The former is less secure (so better to only store those shortcuts in a place that no other users can access).
From the ISQLW.exe syntax documentation:
Syntax
isqlw
[-?] |
[
[-S server_name[\instance_name]]
[-d database]
[-E] [-U user] [-P password]
[{-i input_file} {-o output_file} [-F {U|A|O}]]
[-f file_list]
[-C configuration_file]
[-D scripts_directory]
[-T template_directory]
]
The parameters /S, /U, /P and /E are very similar to the -S, -U, -P and -E ones from SSMS.exe (SQL Server Management Studio) with one distinction: there MUST be a space between each parameter and the value:
- SQL Server Management Studio (using SQL Server username and password):
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" -S "servername[instancename]" -U "username" -P "password"
- SQL ServerManagement Studio (using credentials for the currently logged in windows user):
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" -S "servername[instancename]" -E
Read the rest of this entry »
Posted in Batch-Files, Database Development, Development, Power User, Scripting, Software Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | 5 Comments »
Posted by jpluimers on 2012/02/08
Most Batch files for detecting Windows versions try to parse the either the [WayBack] output fromVER or the [WayBack] output from SYSTEMINFO [WayBack], but forget that there many Windows installations are not English. Some even use WMIC, but [WayBack] WMIC is only available for administrators and not available some flavours like XP Home.
Languages issues are always important to watch for. The Dutch Windows XP returns Microsoft Windows XP [versie 5.1.2600] which is just one word different from the English Microsoft Windows XP [Version 5.1.2600]. Other languages may differ even more.
This batch file tries to circumvent the language differences, uses VER and works at least with Dutch and English Windows versions of XP and 7, most likely with many other languages and versions as well.
On a Windows XP SP3 machine, it lists WindowsVersion=5.1.2600 and on a Windows 7 SP1 machine it lists WindowsVersion=6.1.7601.
One possible addition would be to [WayBack] detect x64 or x86.
The detection assumes that VER will emit the version in [angle] brackets, and uses two batch file for loops to get the text in between them using the [WayBack] tokens and delims for loop parameters in the first for loop right behind the begin label and the second for loop right after the parse1 label.
Then it splits the remaining text using spaces at the parse2 label, and takes the right most portion using the [WayBack] shift command at the parse3 label.
Many thanks to [WayBack] Rob van der Woude for a lot of interesting batch file documentation. Read the rest of this entry »
Posted in Batch-Files, Power User, Scripting, Software Development, Windows, Windows 7, Windows XP | Leave a Comment »
Posted by jpluimers on 2012/02/07
When Google searching, most results for the Outlook 2003 Signature Folder Location AppData give you the wrong folder.
They mix environment keys like UserName, UserProfile, but should use AppData as that has been the base since at least Windows XP.
This is the correct folder for any Outlook version (2003, 2010, etc): %appdata%\Microsoft\Signatures
Making sure you use the right environment variable is very important, especially in large Windows based environments that often use roaming profiles and a mix of Windows environments.
For instance, at a client they have a mixed environment of Windows XP and Windows 7, with separate AppData locations for the two on a LAN:
- Windows XP:
\\server\DFS\share\Application Data
- Windows 7:
\\server\DFS\share\Application Data.v2
There is a very nice Wikipedia article on the Windows Environment variable that explains this situation in the synopsis.
–jeroen
Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows, Windows 7, Windows Vista, Windows XP | Leave a Comment »
Posted by jpluimers on 2012/01/19
Most batchfile wait examples require a functioning network connection.
Just in case you haven’t, Rob van der Woude has a nice example on his batch file Wait page using the Choice command.
The bummer is: choice is available on almost all Windows versions (actually since DOS 6.x), but not on Windows XP, and not on Windows 2000, but it is there in Windows Vista and up where you can use the timeout command :(
Alternatives can be found in the other examples on Rob’s wait page.
CHOICE – Wait.bat: Uses CHOICE to wait for a specified number of seconds.
By using REM | before the CHOICE command, the standard input to CHOICE is blocked, so the only “way out” for CHOICE is the time-out specified by the /T parameter.
The idea was borrowed from Laurence Soucy, I added the /C parameter to make it language independent.
@ECHO OFF
IF "%1"=="" GOTO Syntax
ECHO.
ECHO Waiting %1 seconds
ECHO.
REM | CHOICE /C:AB /T:A,%1 > NUL
IF ERRORLEVEL 255 ECHO Invalid parameter
IF ERRORLEVEL 255 GOTO Syntax
GOTO End
:Syntax
ECHO.
ECHO WAIT for a specified number of seconds
ECHO.
ECHO Usage: WAIT n
ECHO.
ECHO Where: n = the number of seconds to wait (1 to 99)
ECHO.
:End
–jeroen
via: Batch file examples – Wait.
Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2012/01/17
When appending multiple text files to a big one (for instance to post-processing on the total: dedupe, sort, gather statistics, etc) you often will find one or more of the source files missing a CRLF.
So you will have to insert those carriage return line feed combo’s manually.
Well, mr Jones points out that:
there’s actually an easy way to simply echo a carriage return and line feed instead, by just issuing an echo command followed immediately by a period (no space in between), like this:
echo. >> somefile.txt
Thanks Jared!
–jeroen
via: Dear Mister Jones » How to insert a carriage return with batch.
Posted in Batch-Files, Development, Scripting | Leave a Comment »
Posted by jpluimers on 2011/12/29
Sometimes you want to parse commandline arguments in batch files starting at the last one.
For parsing them left to right, the shift command comes in handy.
But there is no “shift-reverse” command, so you need some trick.
StackOverflow to the rescue: user Joey provides this really nice answer:
The easiest and perhaps most reliable way would be to just use cmds own parsing for arguments and shift then until no more are there.Since this destroys the use of %1, etc. you can do it in a subroutine
@echo off
call :lastarg %*
echo Last argument: %LAST_ARG%
goto :eof
:lastarg
set "LAST_ARG=%~1"
shift if not "%~1"=="" goto :lastarg
goto :eof
:eof
–jeroen
via: Get last command line argument in windows batch file – Stack Overflow.
Posted in Batch-Files, Development, Power User, Scripting, Software Development | Leave a Comment »