Rob van der Woude's Scripting Pages

News Archives 2011 Q2

 

[ Back to the current news page... ]

 

June 27, 2011 • A bug in WANIP.exe has been fixed (corrected a typo in the second URL to try if the first one would fail).
June 25, 2011 • Two minor bugs in Hardware.hta's interface have been fixed.

• A minor update to Paste.exe: the help screen explains the errorlevels better than before.
June 22, 2011 • A potential bug has been fixed in WANIP.exe: the original version used a regular expression \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} to check if a valid IP address was returned.
Since only an IP address should be returned, and nothing else, I changed the regular expression to ˆ\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$ instead.
June 21, 2011 StarDateXP.bat is an update of the earlier NT version; the new version uses WMIC to read the current date and time.
It will save its result in environment variable %StarDate% and display it like this: StarDate=299852.9 BW (Before Warp)
June 20, 2011 WANIP.exe returns the computer's WAN IP address.
It uses 3 different URLs to try and get the address, and it is much faster than my VBScript version using Internet Explorer (unless the URLs all fail to return an IP address).
With the following code, it can be used in a batch file:

FOR /F %%A IN ('WANIP.EXE') DO SET WANIP=%%A

Paste.exe reads and displays text from the clipboard.
I wrote it to use it in conjunction with the latest Hardware.hta version:

HARDWARE.HTA /NoUpdChk /Computer:computer /Copy
PASTE.EXE | MORE /E +1 >> inventory_list.csv


Hover over any part of the commands to display a short explanation.
June 19, 2011 Hardware.hta has been updated once more: a minor bug (?) fix (impatient users can no longer render the buttons disabled), and some command line switches were added to allow unattended use of the HTA.
June 16, 2011 • WMI lists SATA harddisks as IDE, which makes inventories unreliable or of little use.
My latest script, DiskTypes.vbs, is my first attempt at overcoming this limitation. It finds the harddisk controller for each harddisk and CDROM drive, and searches for the words "SATA", "S-ATA" or "Serial ATA" in its Description field.
Not the most reliable method, I agree, but the least unreliable I know that can be used in scripts.
Note that some controllers (usually the ones with RAID capabilities) are incorrectly recognized as SCSI controller, as is the case on my own computer (HDD4, which is identical to HDD0 and HDD3):
		HDD0    WDC WD20EARS-00MVWB0                    SATA    1863 GB
		HDD1    WDC WD10EACS-22D6B0                     SATA     932 GB
		HDD2    ST31500541AS                            SATA    1397 GB
		HDD3    WDC WD20EARS-00MVWB0                    SATA    1863 GB
		HDD4    WDC WD20 EARS-00MVWB0 SCSI Disk Device  SCSI    1863 GB
		HDD5    Generic USB SD Reader USB Device        USB        0 GB
		HDD6    Generic USB CF Reader USB Device        USB        0 GB
		HDD7    Generic USB xD/SM Reader USB Device     USB        0 GB
		HDD8    Generic USB MS Reader USB Device        USB        0 GB
		CDROM0  PLEXTOR BD-R   PX-B920SA                SATA         I:
		CDROM1  HL-DT-ST DVDRAM GH22NS40                SATA         J:

Basic Hardware Inventory (Hardware.hta) has been updated with the very same code used in DiskTypes.vbs, so it too now differentiates between IDE and SATA interfaces for harddisks and CDROM drives.
June 15, 2011 Basic Hardware Inventory (Hardware.hta) has been updated: it now supports up to 8 harddisks, and up to 4 video cards, monitors and network adapters.
June 14, 2011 A spoonbill on the isle of Texel • I just returned from a vacation on the isle of Texel, where my camera worked overtime trying to capture all the beautiful birds that can be found there.
It may take a while to answer all e-mail...

• Several improvements have been made to WMIGen.hta: updated and improved C#, Python, Ruby and VB .NET code, more command line options, and a help popup screen when F1 is pressed.
May 30, 2011 • I added Good Friday to my Holidays Calculator HTA; and it now also supports Italian and Portuguese.
May 19, 2011 • I added F# to WMIGen.hta's list of "export formats".
I also added the new /NOSPACES switch to allow use of the unaltered property names for descriptions.
If no command line switch is used, the settings normally done on the command line can be altered interactively. With the /Q switch this new feature can be blocked.
May 18, 2011 • If you can't find it, write it yourself: TranslateCulture.exe lists translations of weekdays and/or month names for the specified languages ("cultures" in MS speak).
May 17, 2011 • I added Groundhog Day to my Holidays Calculator HTA.
May 16, 2011 GetMyPID.exe returns an errorlevel equal to the calling batch file's PID.
It uses Jared Barneck's ParentProcess class.
To get a batch file's PID requires only two lines of code:

GetMyPID.exe > NUL
SET MyPID=%ErrorLevel%


• More maintenance on the web server tomorrow night:

... expect some downtime or instability for your website between 02:00AM and 04:00AM CET May 18, 2011.
We plan to have everything up and running as normal at 04:00AM CET.

May 14, 2011 • Justin Goldspring found a bug in Brian Williams' Multiply.cmd (multiply big numbers), which Brian corrected immediately.

Thanks Justin and Brian

• Carlos M. updated his A2U.bat (ASCII to Unicode), to allow non-ASCII characters in file names.

Thanks Carlos
May 13, 2011 • Don't forget: today is Blame Someone Else Day.
May 12, 2011 • Brian Williams successfully debugged his GetTitle.bat.
The new version passed all tests in XP and Windows 7.

Congratulations, Brian.
May 11, 2011 • Brian Williams updated and improved his GetTitle.bat.
The new version passed the multiple simultaneous instances test in XP, and almost passed (8 or 9 out of 10 correct) in Windows 7.
I think the difference is caused by my test computers: the Windows 7 computer is really fast, whereas the XP computer is a slow virtual machine.
Brian uses the hundredths of seconds as random number, which fails to be unique if 2 or more consoles are opened within 10 milliseconds.
For everyday use, the batch file will perform flawlessly, unless you schedule it to start simultaneously at exactly the same moment.

Thanks Brian, and congratulations.

• Carlos M. sent an updated GetTitle.bat.
The executable it generates is even smaller than the previous version's.

Thanks Carlos.

WaitASecond.exe is a small utility written in C# to get a random delay of 900..1100 milliseconds.
May 10, 2011 • Carlos M. sent me his script to read its own console window title.
As it generates temporary VBScript code and even an executable, it doesn't qualify for the challenge. It does, however, pass the multiple simultaneous instances test.

Thanks Carlos.

• I updated GetTitle.exe: its new /NC switch will trim the command line if it was appended to the title, and the separate XP version is no longer required since the new version works in "all" Windows versions.
FOR /F "tokens=*" %%A IN ('GetTitle.exe /NC /NP') DO SET Title=%%A is what you need to read the title to restore it later.

• While on the subject, I found the PowerShell command to read the console window title.
May 9, 2011 • Remember the real life batch challenge? I challenged you to write a batch file that will read its own console window title. After reviewing the first results I added some extra requirements: it should also work when multiple console windows are open, and preferably even when multiple instances of the batch file are running.
Several batch scripting gurus sent me their working code, and I tested each script in Windows 7 Ultimate SP1 (64-bit) and Windows XP Professional SP3 (32-bit).
The source code and test results can be found here.

I would like to express my gratitude to all "contestants" for sharing their inspiration - thanks.
April 22, 2011 IsFAT.exe and IsNTFS.exe check if a specified drive is FAT(32) or NTFS formatted.
True scripters would, of course, use WMI, but that wasn't available on my laptops.
April 18, 2011 • You may never have noticed, but up till yesterday a lot of JavaScript and CSS was used to hide my e-mail addresses from harvesters.
I replaced the over 60KB of code by Google's reCAPTCHA Mailhide CAPTCHA generator.

• I made a typo in the code accompanying Carlos M.'s ASCII to Unicode solution. Thanks Jens Ulrik Jacobsen for finding and correcting it.
April 14, 2011 WGetLite.exe is a (very) limited WGET version.
It can be used to display or download text (including HTML) files using HTTP.

RC.bat is a simple batch file written to help me testing scripts and programs; it shows the return code or errorlevel returned by the specified or last command.
It can be used in two ways:
RC command parameters
or:
command parameters & RC
April 13, 2011 • Tonight some maintanace will be done on the web server:

... expect some downtime or instability for your website between 03:00AM and 05:00AM CET April 14, 2011.
We plan to have everything up and running as normal at 05:00AM CET.

Quick, get yourself a copy of TimeShift.bat and calculate when the downtime period will be in your own local time.
Or use PingSite.exe to find out...

GetTxtType.vbs reads a text file's BOM to find out its text encoding (e.g. Unicode 16 BE, or UTF-8, etcetera).
April 12, 2011 • A minor update to IsDST.bat: it performs more validity checks on the specified date and time, and displays specific error messages besides the help text.

IsDate.bat is derived from IsDST.bat.
IsDate.bat checks the validity of a specified date. It uses CMD's internal commands and FINDSTR only.

• And a minor update for PingSite.exe: the /Verbose switch is no longer available, as it was the default behaviour anyway. The new optional /Variable switch will decrease the interval between checks to 20% of the specified time in case of a response code mismatch; to use the /Variable switch, both /Status and /Interval must be used.
April 11, 2011 • A bug has been fixed in IsDST.vbs and GMT.vbs.
Details: the LastDoW( ) function used in both scripts assumed 1 based numbers for the day of week instead of 0 based numbers. This has now been corrected. The code for the actual comparison of the specified date against DST start and Standard Time start has also been optimized.

• A message from Stan Littlefield made me realize that the help text for TimeShift.bat did not make much sense, to say it politely (except maybe to me), so I modified it.
Let me explain: the batch file's goal was to calculate when a USA based web-seminar would start in my local time (Europe/Amsterdam) when its web page mentioned April 9, 2011, 9:00 PM PDT as its start date and time.
So the batch file's first argument is my local time zone, the rest contains the remote date/time and time zone.
The date/time returned are for the local time zone.

Thanks Stan

• I finally managed to get IsDST.bat working.
It did require some really dirty workarounds, like changing the system date up to 65 times to find the DST and Standard Time start dates (all because there is no real batch nor WMI equivalent for the WSH DatePart( ) function; WMI can perform most DatePart( ) functions, but only on the current system date/time, hence changing the system date).
Like the VBScript version, the batch file ignores the "ambiguous hour" right after the transition to Standard Time.
Besides the usual caution, be aware that changing the system date can sometimes block domain access or in rare cases even revoke software licenses.
This batch file was written as a proof of concept; use the VBScript or C# version for real life situations.
April 10, 2011 Max.bat and Min.bat return the highest and lowest value respectively from a list of (signed) integer values on the command line.

IsDST.vbs is a script that checks if the current or specified date is in Daylight Saving Time.
The result is displayed on screen and returned as errorlevel (0 if in DST, 1 if not).

GMT.vbs returns the Greenwich Mean Time for the specified date/time.
It reuses much of IsDST.vbs's code.
April 9, 2011 • Like many of my scripts, TimeShift.bat was born because I needed it myself.
It translates a date/time for a different time zone to local time (or time for any other specified time zone).
It requires PHP 5.2 or later.
April 8, 2011 • A bug was fixed in PingSite.exe: the beep now actually works as expected.
If specified, it will beep on errors too.
The 404 error handling has been improved as well.
April 7, 2011 • Wolfgang Eitel discovered some undocumented command line switches for Foxit Reader:
  • The -displayinbrowser switch forces Internet Explorer and Firefox to open PDF files inside the browser window
  • The -undisplayinbrowser switch forces Internet Explorer and Firefox to open PDF files outside the browser window
Wolfgang found the switches with the aid of SysInternals' ProcessMonitor

Thanks Wolfgang

• As promised yesterday, PingSite.exe has been updated: if the optional /Beep switch is used, it will beep on changes or if the actual response code does not match the expected code.
If an interval is specified, the last response code will also be displayed in the window title.
And last but not least: the returned code will be displayed in red if it does not match the expected code.

A slightly modified example of the (tab delimited) output for the PingSite http://www.mydomain.com/ /Interval:30 /Changes /Status:200 command:

PingSite: 200
[6-4-2011 14:53:01]    200    OK    http://www.mydomain.com/
[6-4-2011 15:11:31]    503    ServiceUnavailable    http://www.mydomain.com/
[6-4-2011 15:12:01]    200    OK    http://www.mydomain.com/
[6-4-2011 20:54:31]    500    InternalServerError    http://www.mydomain.com/
[6-4-2011 20:55:01]    200    OK    http://www.mydomain.com/

 
April 6, 2011 • As I said before, many scripts (and programs) see the light because I need them myself.
PingSite.exe is no exception: my web server has intermittent problems (500 and 503 errors), but when I call the helpdesk it behaves itself just for a while, so I want to monitor it closely.
PingSite.vbs came close to what I needed, but instead of modifying it I rewrote it in C#.
PingSite.exe returns the HTTP response code for the specified URL, or if the optional /Status:nnn switch is used, it returns an errorlevel 0 if the response matches the expected code nnn, or 2 if not (1 is reserved for command line errors).
I also added an optional /Interval switch to run it constantly, and a /Changes switch to display changes in the status code only.
An optional beep may be added later.

An example of the (tab delimited) output for the PingSite http://www.mydomain.com/ /Interval:30 /Changes command:

PingSite
[6-4-2011 14:53:01]    200    OK    http://www.mydomain.com/
[6-4-2011 15:11:31]    503    ServiceUnavailable    http://www.mydomain.com/
[6-4-2011 15:12:01]    200    OK    http://www.mydomain.com/
[6-4-2011 20:54:31]    500    InternalServerError    http://www.mydomain.com/
[6-4-2011 20:55:01]    200    OK    http://www.mydomain.com/

 
April 4, 2011 isDST.exe is a small utility written in C#.
It returns an errorlevel 0 if a specified date is in Daylight Saving Time, 2 if not, or 1 in case of (command line) errors.
I have tried to write it in batch, and I still believe it is possible, but it became far too complex. The essential DST check in C# is only about 3 lines of code...
But for those who want to try: I used WMIC with Win32_LocalTime and Win32_TimeZone.

CapsLock.exe, NumLock.exe and ScrollLock.exe are 3 "ports" of earlier (VB) utilities to C#.
All three of them return an errorlevel 0 if the key lock is off, 2 if on, or 1 in case of (command line) errors.
Adding optional parameter 0 sets the key lock off, 1 sets it on.
The optional /Quiet switch suppresses all screen output.

 

Archived News pages
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.0037 seconds