Rob van der Woude's Scripting Pages

News Archives 2014 Q3

 

[ Back to the current news page... ]

 

September 26, 2014 • Yahoo decided to block mail from all customers of One.com, which happens to be my website hosting and mail provider.
So if you want to send me a message, and expect an answer, please use any mail provider but Yahoo.

• Based on some batch code I had to check, two more tests were added to BatCodeCheck.exe: a test for an excess number of delimiters in a FOR /F loop, and a test for wildcard characters in IF comparisons.
Though both conditions are not always errors (you can use 16 delimiters, and you may check if a string contains a literal asterisk), it doesn't hurt to check and make sure.
September 24, 2014 BatCodeCheck.exe is a complete redesign and rewrite of BatHL.exe.
Both tools check (validate) batch files for common mistakes, e.g. common typos, unterminated quotes, parenthesis and percent signs, undelayed variables while delayed variable expansion is active, etc.
It is still in its early beta stage, but feel free to use and test it.

• Steven Rosenshine found an omission on my Verify if Variables are Defined page: the command
IF "%MyVar%"=="" (ECHO MyVar is NOT defined) ELSE (ECHO MyVar IS defined)
would say MyVar IS defined when run on the command line, even though the variable was not defined at all.
I should have mentioned (and as a matter of fact, I now have) that this test is intended for batch file use only.
For some reason CMD.EXE interprets undefined variables as literals on the command line, and as plain undefined variables in batch files.

Thanks Steven

MessageBox.exe has been updated: an optional timeout has been added.
September 23, 2014 InputBox.exe has been updated: a new optional switch /T:seconds makes the dialog box time out after the specified interval.
September 22, 2014 • A minor update for MessageBox.exe: it now also writes its help text to Standard Error, besides showing it in a MessageBox.
September 16, 2014 OpenFolderBox.exe has been updated: it now hides the "Make New Folder" button by default, with the new optional switch /MD the button can be displayed again, and command line parsing has been improved.
September 12, 2014 InputBox.exe has been updated again: a new optional switch /S inserts a "Show password" checkbox, and command line parsing has been improved.
September 10, 2014 InputBox.exe has been updated: it now accepts newlines in the prompt (\n), both window width and height can be set, and an optional command line switch /P masks the input text (for passwords).
September 9, 2014 DropDownBox.exe is a new batch tool to present a DropDown dialog and return the selected text on screen; like CHOICE with a GUI.
September 7, 2014 DateTimeBox.exe is a new batch tool to present a Date/Time Picker dialog and return the selected date/time in the specified output format.
September 3, 2014 • A new version of PrinterSelectBox.exe is available.
The original version used Windows' own Print dialog, the new version has a more "Spartan" interface without the bells and whistles that were of no use in the old version.



On the command line you can specify the window title, the selected printer (full name or regular expression), and the dialog width.
The batch code to select a printer did not change since version 1.00, except for the optional command line arguments:
SET Options="Select a PDF printer" "PDF"
FOR /F "tokens=*" %%A IN ('PrinterSelectBox.exe %Options% ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET Printer=%%A

Etc.

• I created a new page for all these new "Box" utilities: Neat Dialog Boxes in Batch Files.
August 28, 2014 PrinterSelectBox.exe is a new batch tool, written in C#, to present a Print (Printer Select) dialog and return the selected printer name.



The following batch code uses PrinterSelectBox to select a printer:
FOR /F "tokens=*" %%A IN ('PrinterSelectBox.exe ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET Printer=%%A
IF "%Printer%"=="Cancel" (
    ECHO You clicked "Cancel"
) ELSE (
    IF "%Printer%"=="Error" (
        ECHO An error occurred
    ) ELSE (
        ECHO You selected "%Printer%"
    )
)


OpenFolderBox.exe is a new batch tool, written in C#, to present a Browse Folders dialog and return the selected folder's full path.
The following batch code uses OpenFolderBox to select a folder:
FOR /F "tokens=*" %%A IN ('OpenFolderBox.exe ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET Folder=%%A
IF "%Folder%"=="Cancel" (
    ECHO You clicked "Cancel"
) ELSE (
    IF "%Folder%"=="Error" (
        ECHO An error occurred
    ) ELSE (
        ECHO You selected "%Folder%"
    )
)

Note that the Browse Folders dialog also presents options to delete folders or create new folders.
To prevent unauthorized folder manipulations, you may want to run your batch file with limited permissions, e.g. PSEXEC -l yourbatchfile

SaveFileBox.exe presents a Save File dialog box, and returns the selected file path.
The following batch code uses SaveOpenBox to enter the target path for a Perl file:
SET Options=D:\SourceFiles\Perl "Save File As..." /F
FOR /F "tokens=*" %%A IN ('SaveFileBox.exe "Perl files ^(*.pl^)^|*.pl" %Options% ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET TargetFile=%%A
IF "%TargetFile%"=="Error" (
    ECHO An error occurred
) ELSE (
    IF "%TargetFile%"=="Cancel" (
        ECHO You pressed "Cancel"
    ) ELSE (
        ECHO You selected "%TargetFile%"
    )
)


OpenFileBox.exe has been updated: if an invalid folder was specified, it would ignore the error and use the "last known good".
The new version will abort and display an error message for invalid folders.
August 26, 2014 • Next in line in our DialogBox series: OpenFileBox.exe.
As the name suggests, it presents an Open File dialog box, and returns the selected file path.
The following batch code uses FileOpenBox to select a Perl file for copying:
SET Options=D:\SourceFiles\Perl "Select a Perl file"
FOR /F "tokens=*" %%A IN ('OpenFileBox.exe "Perl files ^(*.pl^)^|*.pl" %Options% ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET PerlFile=%%A
IF "%PerlFile%"=="Error" (
    ECHO An error occurred
) ELSE (
    IF "%PerlFile%"=="Cancel" (
        ECHO You pressed "Cancel"
    ) ELSE (
        ECHO You selected "%PerlFile%"
    )
)

If you don't need extensive error checking, use the following code instead:

SET Options=D:\SourceFiles\Perl "Select a Perl file"
FOR /F "tokens=*" %%A IN ('OpenFileBox.exe "Perl files ^(*.pl^)^|*.pl" %Options%') DO SET PerlFile=%%A
IF NOT "%PerlFile%"=="" ECHO You selected "%PerlFile%"
August 24, 2014 InputBox.exe has been updated: it no longer displays the entered text on screen if "Cancel" is clicked.
August 22, 2014 InputBox.exe is a new batch tool, written in C#, to popup an InputBox from a batch file.
The text from the input field is written to Standard Output (the screen) if the "OK" button is clicked.



The optional command line arguments can be ignored if you don't need them, but you cannot just skip any argument and use the one following it.
E.g. InputBox "Prompt" "Title" "Default value" 300 is correct, but InputBox "Prompt" 300 will use "300" for the title!
The following code uses MessageBox.exe in a batch file:
SET Prompt=What is your name?
SET Title=Enter your name
SET Default=John Doe
SET Width=500
FOR /F "tokens=*" %%A IN ('InputBox "%Prompt%" "%Title%" "%Default%" %Width%') DO SET Answer=%%A
ECHO You entered "%Answer%"

Note that you cannot catch InputBox.exe's "errorlevel" with a simple IF NOT ERRORLEVEL 0 ... in the line following the FOR loop.

Most of the C# code comes from Gorkem Gencay on StackOverflow.com.

Thanks Gorkem
August 21, 2014 MessageBox.exe has been updated: support for linefeeds and tabs in the message text has been added, and I decided to add more options that are available in the MessageBox class:



The new command line arguments can be ignored if you don't need them (in fact all arguments are optional), but you cannot just skip any argument and use the one following it.
E.g. MessageBox "Message text" "Title" OKCancel Stop Button2 is valid, but MessageBox "Message text" "Title" OKCancel Button2 is not!

The following code uses MessageBox.exe in a batch file:
SET Prompt=The operation failed.\nWhat do you want to do now?
SET Title=Error
SET Options=AbortRetryIgnore Warning Button2
FOR /F %%A IN ('MessageBox "%Prompt%" "%Title%" %Options% ^|^| ECHO error') DO SET Answer=%%A
IF "%Answer%"=="error" (
    ECHO Command line error
) ELSE (
    ECHO You clicked %Answer%
)

Note that you cannot catch MessageBox.exe's "errorlevel" with a simple IF NOT ERRORLEVEL 0 ... in the line following the FOR loop.
August 20, 2014 WMIGen.hta (the WMI Code Generator) has been updated: its improved update check allows you to automatically download and install future updates, and a setting has been added to change the HTA's style to black and white for better contrast (a matching command line switch /BW was added too).

Paste.exe has been updated: instead of having to redirect its Standard Output to a file, you can now specify the file name it has to write to (if not specified, it will write to Standard Output like it did before).

MessageBox.exe is a new batch tool I wrote to display messages in a MessageBox, like VBScript, with more options.


I wrote it because displaying messages in a GUI has become harder: NET SEND has been discontinued entirely, and MSG.EXE is not available in Windows * Home Editions.
August 8, 2014 • Several months after Windows 8 update KB2919355 failed with error 80070002 on my netbook, I finally found the cause.
Or actually: Andrey Tarasevich did.
I added his solution to my Tweaks page, it may prevent others from pulling out their hair.

Thanks Andrey

• (The 1.30 update of UpdateCheck.hta has been withdrawn)
August 1, 2014 • For a friend I wrote MTUTest.bat, a simple batch file to check if the MTU setting for the (only) enabled network adapter is optimal or not.
It is based on a tutorial by Harrison Fleetwood.

Thanks Harrison
July 24, 2014 • Mark Dekker found a logic error ("bug") in Which.vbs: it would iterate through the extensions listed in %PATHEXT% first, then through the folders listed in %PATH%, whereas the command processor iterates through the folders list first, and then through the extensions list.
The new version correctly follows the command processor's "procedure".
To implement this change I had to terminate the optional /L (return Latest version) switch, unfortunately.
You can still check the versions with the /V (display Version) and /A (show All matches) switches, however

Thanks Mark
July 23, 2014 • Craig Burson found a bug in VBS2CMD.vbs: the generated batch file would often be saved in the parent folder of the VBScript file.
The author of the script, Denis St-Pierre, intended the batch file to be saved in the same folder as the original VBScript.
The cause was the way the output path was generated, by concatenation of the VBScript file's parent folder and the batch file's file name:
strFileNameOUT = objFSO.GetParentFolderName( strFileNameIN ) & objFSO.GetBaseName( strFileNameIN ) & "_CONVERTED.CMD" (line 76 in the old script)
The solution was to use the FileSystemObject's BuildPath method; this will automatically insert a backslash if necessary:
strFileNameOUT = objFSO.Buildpath( objFSO.GetParentFolderName( strFileNameIN ), objFSO.GetBaseName( strFileNameIN ) & "_CONVERTED.CMD" ) (line 77 in the current version).

Thanks Craig and Denis
July 21, 2014 • Robert Cruz sent me a useful tip on escaping doublequotes in the search pattern of a FIND command: use double doublequotes.

Thanks Robert
July 11, 2014 • David Brian Morgan found an error in UpdateCheck.ini: the ProgName and Win32Product values for File Commander/W were mixed up.
Besides, a change in the version history on the SnagIt website necessitated a modification in the INI file.
I also made a minor change in UpdateCheck.hta: if the latest version for a program cannot be determined, clicking the "Check" button will open the web page specified for the version check, instead of the download page.
The updated HTA and INI files are now available for download.

Thanks David Brian
July 8, 2014 UpdateCheck.hta has been thoroughly updated: new ways to check installed program versions have been added, new command line arguments allow "silent" runs without user interaction unless updates are found, and detailed Help and Reference pages have been added.
And of course, while at it, I also added several new programs to the INI file.

 

Archived News pages
Archived news from 2014
Archived news from 2013
Archived news from 2012
Archived news from 2011
Archived news from 2010
Archived news from 2009
Archived news from 2008
Archived news from 2007

 


page last modified: 2018-04-16; loaded in 0.0073 seconds