stepbytech

Step by Step Directions for Techs

Category Archives: Scripts

Timestamp USB drives used in deployment

I have found that when testing MDT deployments, I end up with a lot of USB drives and people asking for them to be updated. Inevitably, someone uses an old one to image and the complaints come rolling in.

This is a simple script that creates a file with a name that is a time stamp. That way, I know when I created the media.

—————————————————————————————–
REM mmddyyyy
For /F “tokens=2-4 delims=/ ” %%a in (“%DATE%”) DO SET MDY=%%a%%b%%c
REM hhdd
FOR /F “tokens=1,2 delims=:” %%d in (“%TIME%”) DO SET ORAS=%%d%%e

REM output to file
echo TimeStampFile > \\servername\sharename\%MDY%_%ORAS%.txt

—————————————————————————————–

I save the file to the share that MDT copies the media to. That is done in the last time with \\servername\sharename. It produces a TXT file with the date and time in it. Right now it is Jan 20th, 2014 at 10:23 AM. The file name is 01202014_1023.txt.

Works great. Less filling.

Silent install isn’t working, but I need to automate this!

Never fear, a script is here (kinda).

Recently I was working to automate the installation of a poorly written program.  For the life of me this thing would not install quietly.  Repackaging it failed and I was running out of time.  I choose to install the program and pass the appropriate keystrokes to it.

Note: This is not advised when rolling applications out if the user is at the keyboard.  One click to another application and this all goes haywire.

So what I did what create an install.vbs script that looks a bit like this:

Set objShell = WScript.CreateObject(“WScript.Shell”)

‘This pulls up the “Setup” window as the active window
Do Until Success = True
    Success = objShell.AppActivate(“Setup”)
    Wscript.Sleep 1000
Loop

‘Takes a bit before the application can take inputs.  This is 6 seconds
Wscript.Sleep 6000

objShell.SendKeys “{ENTER}”
Wscript.Sleep 1000

objShell.SendKeys “%A”
objShell.SendKeys “{ENTER}”
Wscript.Sleep 1000

objShell.SendKeys “{ENTER}”
Wscript.Sleep 1000

objShell.SendKeys “{ENTER}”
Wscript.Sleep 1000

objShell.SendKeys “{ENTER}”
Wscript.Sleep 1000

objShell.SendKeys “{ENTER}”
Wscript.Sleep 1000

‘This clicks the install button
objShell.SendKeys “{ENTER}”

‘It takes a little bit to install it
Wscript.Sleep 30000

‘Close configuration window by pressing Alt-D-E
objShell.SendKeys “^DE”

‘Click finish
Wscript.Sleep 5000
objShell.SendKeys “{ENTER}”

Once you have that, you launch the setup program (you can do that in this script or in another one.  However, if you do it from a batch file, you need to use  a start command (otherwise it waits for the process to finish before moving on):

start “” “%~dp0setup.exe”
start “” “%~dp0install.vbs”

Note: The %~dpo is a shortcut that uses the current directory it is being run out of instead of hard coding the paths.

As you can see, there is a bit of timing you have to get down.  That is just trial and error.  I used a virtual environment and snapshots to get the it working so I could always install on a “clean” system.

If there are other keystrokes you need, here is where I got them:
http://technet.microsoft.com/en-us/library/ee156592.aspx