Windows, Batch File Internet calls

Microsoft Windows batch files can be written for many things, one thing thats hard to do is send a notice to a central server on the Internet when they complete. Here is how to do that.

The windows batch command line language can make use of the BITS service to send a notice when its complete -- even a status message.

Since Windows 2000 there has been the BITS background downloader command. Called properly from the command line it can be used to retrieve/upload files, or simply perform an HTTP HEAD GET against a web service or server. It is scheduled to be deprecated, but still available in Windows 8. That covers a wide swath of windows versions 2000, XP, Vista, 7, 8 and their server versions.

Most Web servers record HTTP requests which includes the source IP address and the document that is being requested. This can be used as a default recorder for the messages.

Microscopic Web Server

Different versions of BITS behave differently.

Older versions may simply perform an HTTP GET

Newer versions perform an HTTP HEAD first, then a GET. On some web servers the reception of a HEAD request before a GET may produce an error on the server or the client if the 'out of order HEAD requesd method comes first.

What BITS is attempting to do is to determine if the previous download has completed and decide whether to resume that download or begin a new one. The BITS client may proceed to the GET stage, but the web server may have already closed the connection.

So with reservation, one should make sure the web server being used as the recorder for notifications can itself behave accordingly if the inital connection is from a version of BITS that preceeds a GET with a HEAD request. IIS will suport this... other web servers may simply record the request and wait for the following GET request, others may close the connection.

BITS will complete the request and return status information, which can be ignored. The real goal was to submit a one line informal message into the web server log in the form of a request which is logged.

This works well as a pseudo syslog service, or Internet enabled logging system.

Since the logs are "tagged" with the IP address of the remote system and any arbitrary strings in the request, multiple calls can be made from the batch script to essentially provide a one-way communications of lots of diagnostic information and filtered later to collate by IP, string or timestamp to reconstruct a running dialog with that batch file.

There is also the possibility of formally "uploading" a status report for processing later. Making this method even more robust. But really the goal for this demonstration is simply that a quick notification can be sent out by a windows batch script - without resorting to powershell, vbscript or other heavier methods.

The Windows Update and Microsoft Update patch system relies upon this service, so even if deprecated it will apparently continue to be available from a cmdlet within Powershell in the future. In which a single ps cmd could be issued from within a windows batch file to cover Windows 2000 through Windows 10.