Date and time stamp in your batch files

Posted by Steve Wiseman on November 15, 2009 with 1 Comments

There has been some activity recently in an old 2007 post I wrote about creating a date and time stamp in your batch files.

Well, the funny part was that I said ‘Date and Time’ in the subject, but I only talked about pulling out the current date.

Sue asked “What if I need both date, and time?”

Good question. What if you want to create a file that has the current date and time for each execution of the script?

In my old article I was creating zip files, using an imaginary command line based zip program. So in my article here I am going to make our goal to zip up a folder and name it:

YYYYMMDDHHMMSS_DATA.zip

If it were run today, our script should create a file by this name:

20091111143900_DATA.zip

To accomplish this, you need to use substring batch codes. If you want more detail on how these work, I explain it in the original article:

Create a date and time stamp in your batch files

To get the current time we use the %TIME% environment variable, and %DATE% for the date.

Using the substring batch codes from my old article, this is how we would pull out the year, month and day:

%date:~-4,4%%date:~-10,2%%date:~-7,2%

How about the time? That can be a little more difficult since the numbers returned from the time are not always the same length. For example, if it is 9 o’clock, it will say 9:00 – not 09:00. This will cause trouble when using the value for our filename.

Before we deal with that space, let me show you the substring codes to pull out the time:

Milliseconds: %time:~-2,2%
Seconds: %time:~-5,2%
Minutes: %time:~-8,2%
Hours: %time:~-11,2%

So naturally, if we wanted HHMMSS we could take those values above and put them side by side:

%time:~-11,2%%time:~-8,2%%time:~-5,2%

But like I said before, the hours can give you trouble because of the space. I came up with this code to pull off the space:

SET HOUR=%time:~-11,2%
Call :TRIM %HOUR%
GOTO :EOF
:TRIM
Set HOUR=%*
:EOF
REM You would use your trimmed hour right here
@echo %HOUR%

So, pulling it all together, how would we get an environment variable filled with a good date and time stamp filename?

Here is the code:
REM Get the hour first and put in an environment var

SET HOUR=%time:~-11,2%
Call :TRIM %HOUR%
GOTO :EOF
:TRIM
Set HOUR=%*
:EOF

REM Create our timestamp filename variable
SET DATESTMP=%date:~-4,4%%date:~-10,2%%date:~-7,2%%HOUR%
SET FILENAME=%DATESTMP%%time:~-8,2%%time:~-5,2%_DATA.ZIP

REM This is just an example call using our new filename
REM -=The real PKZIP program probably uses a different command line syntax
pkzip.exe c:\ImportantFolder\*.* c:\ZIPFILES\%FILENAME%

Using the code above, you can easily generate new files using the date and time in your batch script.

Original Article from www.networksteve.com

Network Administrator – Beta 4 Released

Posted by Steve Wiseman on October 8, 2009 with 4 Comments

We are right on track with our beta – Network Administrator Beta 4 has been released.

You can get a copy of the beta from here:

Network Administrator Beta 4

As I wrote last week, we were working on the remote execute engine within Network Administrator. I am pleased to say that it is complete.

As a result of that implementation we were able to add two new plugins. They are:

Change Network Settings

Switch a computer to DHCP, or update the DNS Settings to different servers

Change Network Settings

Remote Execute

This allows you to remotely execute a vbscript, batch file, MSI installer (It automatically makes it quiet for you), or command line program. This is a very powerful addition, since it gives you the ability to create a script, and push it across all the machines on your network. One other point to note about this is that this will be faster than you doing this yourself from the command line using tools like PSExec. This is because Network Administrator will spawn more than one process at a time to accomplish your task.

Remote Execute Plugin

If you missed my post last week, we promised 10 plugins by the time we release on October 30th. In addition to the two I just discussed, here is what we have created so far:

Mass Folder Copy – This plugin allows you to pick a folder on your hard drive, and copy it to many machines across your network. Perfect way to copy a set of shortcuts to everyone’s desktop.

Offline Files Disabler – Disables the annoying offline files setting in Windows XP, and 2003.

Logon Disclaimer – Allows you to set a logon disclaimer that is displayed to a user before they login.

Wallpaper Set – You can set a common background wallpaper image, and set options such as tile, stretch, and center.

One of our next plugins will allow you to change the password of a local admin user account. It is easy to change an Active Directory user account, but when an admin leaves, you still have those local account passwords floating around. This would allow you to change it in a few moments – across your entire network.

Get your suggestion in by mailing us at plugins@intelliadmin.com We cannot answer all of the emails sent, but we do read them all.

Give it a spin, and let us know what you think.

Pre order your upgrade of Network Administrator 3.0 for only $99 (Includes a copy of 2.9)- Don’t wait – It will be $199 when it is released on October 30th. Click here to purchase

Get Windows Update on a DVD

Posted by Steve Wiseman on September 16, 2009 with 2 Comments

I was reading an article at PCMag about PatchMateXP. They have had all the patches for XP on one convenient CD.

Unfortunately for PatchMateXP, this breaks a license with Microsoft and they shut themselves down before they got into legal trouble.

This got me thinking – is there a way to get MS Updates on DVD or CD?

My findings were quite interesting.

After tons of digging, I found this Microsoft Knowledge base article: 913086

At that link, Microsoft provides ISO files that contain all of the security updates by month. They update it regularly.

This works fine if you are already patched up, and just need a few months. What if you need all of the patches for Vista, XP, or 2003? That won’t really help.

I dug some more, and I came across a free utility called Offline Update. You can download it from here.

It allows you to create an ISO file with patches for a specific version of Windows. It gets around those pesky legal issues by having you download the patches to generate the ISO file.

To use it, download the package from the above website, and extract it into a folder. In the root directory you will find a program named UpdateGenerator.exe

Launch it, and you will see that it has a simple, but effective interface:

Offline Update 6

It even includes patches for Office – a nice bonus.

Select the patches you want, and click start.

A command line window will popup and it will download for hours or days, but eventually it will finish.

When it completes, you will find the completed ISO file in the folder named ISO under the root:

Offline Update ISO

In my case it was the 64 bit version of 2003/XP patches.

Want to know the coolest part?

The ISO it builds is more than a collection of patches, it includes a custom program that will automatically install all of them in one shot.

Simply pop your burned DVD into the drive, and a window will show up:

Offline Update Program

Don’t be confused by the list of options, it is just giving you a choice on non-patch items included in the ISO.

If you just want the patches, simply select nothing and click start. It will only install the patches that have not been installed on your system:

Offline Install Patches

That is all there is to it. The program will install all of the patches, reboot, and the system is up to date.

Now, I can burn that ISO, and give it to my friend Brett, since he lives in an Internet dead zone.

This little utility can be a huge time saver. I highly recommend it.

Monitor Network Traffic

Posted by Steve Wiseman on July 27, 2009 with 0 Comments

Last week I wrote about a free tool from Microsoft for synchronizing files. I asked you if you had any tools that made your life easier – my inbox was filled with suggestions.

One of the free tools that really caught my eye was Microsoft Network Monitor. I have been using Ethereal for a long time. It too is a great tool for monitoring network traffic.

Microsoft network Monitor 3.3 gives it a run for its money. Some quick points that make me like it:

It identifies processes that are generating the traffic:

Process View

It includes a ton of parsers that can pull out common protocols like HTTP, SMB, FTP, etc. These make it much easier to read what you are looking it:

Network Monitor Parsers

Easy selection of network cards to monitor:

Select Network Cards

It has an extensive filtering system to weed out packets you are not interested in:

Network Filters

In addition, it has many command line options to automate it without any interaction.

Check it out at:

Microsoft Network Monitor 3.3

Delete files securely

Posted by Steve Wiseman on May 13, 2009 with 0 Comments

Since 2000 every version of Windows uses object reuse protection. When you create a file, the space on the hard drive for that file will be zeroed out.

Another way of looking at this is when a file is created, Windows will make it impossible to see what was there before.

But what about right after you delete a file? Nothing has been written to that space yet. What is on the physical hard drive? The entire file of course. Not good if the file is highly confidential.

What if you wanted to delete a file securely?

There are plenty of tools out there that can do this, and most of them cost quite a bit of money. But there is a free alternative.

It is called SDelete and it is from Microsoft:

http://download.sysinternals.com/Files/SDelete.zip

How does it work?

Simply download the program and run it from the command line. By default it will only complete 1 pass when erasing a file. I would suggest overriding that with a higher number – the higher the better, but it will be slower.

Lets delete a file with it, using 25 passes:

sdelete.exe -p 25 FileToDelete.zip

This will securely delete FileToDelete.zip

SDelete implements the Department of Defense clearing and sanitizing standard DOD 5220.22-M. This will give you confidence that once deleted with this tool, your file is gone forever. Note that it does delete the file, but the file name is still recoverable from the file system (Make sure the file name itself does not have any revealing information).

The full list of possible commands for SDelete are:

usage: sdelete [-p passes] [-s] [-q]
sdelete [-p passes] [-z|-c] [drive letter]
-c Zero free space (good for virtual disk optimization)
-p passes Specifies number of overwrite passes (default is 1)
-q Don’t print errors (Quiet)
-s Recurse subdirectories
-z Clean free space

It supports wildcards too. So if you wanted to securely delete an entire folder you can call it like this:

C:\>sdelete c:\temp\*.*

SDelete – Secure Delete v1.51
Copyright (C) 1999-2005 Mark Russinovich
Sysinternals – www.sysinternals.com

SDelete is set for 1 pass.
c:\temp\Eula.txt…deleted.
c:\temp\Import.csv…deleted.
c:\temp\readme.txt…deleted.
c:\temp\sdelete.exe…deleted.
c:\temp\VCdControlTool.exe…deleted.
c:\temp\VCdRom.sys…deleted.

If you have files that need to remain secure, SDelete is a great way to make sure they are removed from your hard drive.

Write script results to the event log

Posted by Steve Wiseman on May 12, 2009 with 0 Comments

I have quite a few scripts that are run by task scheduler on my server.  One of the ways I track the results is by writing to a text file in a common share. After a while this can become a little ridiculous to follow.

Recently I discovered that it is possible to create your own Application, or System events from a script that will show up in the Windows event viewer.

To create your own events, you need to use the “eventcreate” command line argument. This command line program is available in Windows XP, 2003, Vista, and Windows 7 – unfortunately not in Windows 2000.

How can you use it?

Let me take a simple example, and then I will walk you through writing an event to the log. In one of my scripts I have an xcopy that I check for errors:

@echo off

xcopy c:\temp c:\temp2 /y /i /c

if ERRORLEVEL 5 GOTO ERROR
if ERRORLEVEL 4 GOTO ERROR
if ERRORLEVEL 1 GOTO ERROR

REM SUCCESS

goto exit

:ERROR

REM FAILURE

:EXIT

The above script looks for the different error codes that XCOPY can return – right now we won’t concentrate on that. What we want to do is add our EventCreate command right around where we have our “REM FAILURE”

There are a few details we need to collect together before we can call our command. First we want to determine which event log we want to write.

For our example I want to pick the “Application” log

Then, we need to determine an event source. The event source specifies the text that will be shown as the source in the log. The trick is you need to pick something unique that won’t have a name conflict with Windows, or other scripts. This means don’t pick DNS, VSS, or W32Time – or any common windows service name. At the same time, no spaces, and keep it short.

I picked XCOPYRESLT

Next we need to pick an event type. Our choices are Information, Warning, or Error. In the case of my example, I am only going to report errors so the obvious pick is “Error”.

What else? Well an event ID is needed. This is an arbitrary number that you may pick to suite your own custom needs. 1000 sounds good to me.

And finally, a description. “Domain Controller XCOPY Failure” seems like an easy description.

Now, lets bring it all together at the command line:

eventcreate /l Application /so XCOPYRESLT /t Error /id 1000 /d “Domain Controller XCOPY Failure”

One run at the prompt:

XCOPY Event Error

Now, if we take a peek at the event log:

Custom Event Log Entry

So there you go. Custom event log items right from your batch file. For more detailed information on the eventcreate command, visit this section on Microsoft Technet.