×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBScript FAQ

Imaging and Archiving Systems

Free & Legal OS Archiving Solution by computerhighguy
Posted: 10 Aug 07 (Edited 14 Aug 07)

I worked for a very cheap company that wouldn't buy Ghost licenses.  Most IT Departments would simply pirate the software, but we had to follow SOX and I wasn't going to be responsible should we get busted.  The following script is part of my Bart's PE CD and USB drive.  

VBScript Support for BartsPE
http://cid-5a23ec17d19c088e.skydrive.live.com/self.aspx/PE/VBScript.cab

Note:  This is designed as an archiving solution.  It really isn't designed to archive and then bring down on another system (although it can).  Please keep in mind that there is one limitation to Drive Image XML (the free imaging software I use).  You cannot bring down an image on a partition smaller than the original one.  The only time this is an issue with me is when I am creating a master image for my Imaging solution (coming soon).  In these rare cases, I wait for DIRM to complete and then I boot up GParted and resize the partition to as small as I can (around 7GB usually).  If you know of any free partition resizing programs that work on 32 bit windows, let me know.  I would love to add that to this script.  It is really the only thing keeping it from being a "perfect" solution. :)

markpoulton at hotmail dot com

No laughing at my code.  I am a network engineer by trade, not a programmer.

' // ********************************************************************
' //               Free Computer Archiving (Imaging) Solution
' //
' // I developed this solution for a company who didn't want to pay for
' //  licenses of ghost or any other imaging solution.  This sytem was
' //  specifically developed for use on a Bart's PE disk using
' //  Windows Server 2003 R2 SP1 x86 as the OS (SP2 should work)
' //  Drive Image XML is free (google it) and they even make a plug in for
' //  Bart's PE.  DIRMS is free and there is plug in available for it as well.
' //   To make the Bart's PE disk work, you will need a few things.
' //    1) VBScript support
' //    2) XPE (Although technically optional, it makes life much easier)
' //  
' //   Look for my other scripts for a "totally free" imaging solution
' //  
' //                                            -- ComputerHighGuy

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

' // Path to the dixml.exe file (Drive Image XML is a free imaging product)
' // Remeber that Bart's PE uses very different pathing.  This is the default
' // For the plugin they provide
DIXMLPath = "%SystemDrive%\programs\dixml\dixml.exe"
' // Path to where you will be imaging the system to.  Cannot us UNC pathnames for this.
oldImagePath = "I:\Old Ghost Images\"
' // Location of the DIRMS.exe file.  DIRMS is a free utility that allows you to defrag and consildate the file
' //  on a hard drive to the front of a hard drive.  This helps to make the drive image smaller and speeds up the
' //  time to image.
dirmsPath = "%systemdrive%\programs\dirms\dirms.exe"

' // Get the current year to image to
' // Cannot really use the following command: CurrentYear = Year(Date)
' // The above command will work, but there is no way to ensure that the systems's clock is accurate
' // For example, if a laptop batter goes dead, the internal clock resets to an earlier year.
' // It is easier to just specify the year especially when dealing with less technical people. :)
CurrentYear = "2007"

' \\ Check to see if the current year directory exists
' \\ -1 = exists    0 = doesn't exist
isFolder = objFSO.FolderExists(oldImagePath & CurrentYear)

if isFolder = 0 then
    'wscript.echo "Doesn't Exist"
    set makeFolder = objFSO.CreateFolder(oldImagePath & CurrentYear)
end if

answer = msgbox(vbtab & vbtab & "COMPUTER ARCHIVING SYSTEM (CAS)" & vbCRLF & vbCRLF _
        & "Welcome to the  IT group's Laptop and Desktop Computer Archiving System (CAS)!" & vbCRLF & vbCRLF _
        & "CIS is designed to be run exclusively from a " & vbCRLF & vbTab _
        & "BartsPE disk and is designed primarily for Dell systems."  & vbCRLF & vbTab _
        & "(May work on others though)" & vbCRLF & vbCRLF _
        & "This program will archive the current system to the images folder." & vbCRLF & vbCRLF _
        & "The time to image will vary per system." & vbCRLF & vbCRLF _
        & "Tasks to be complete:" & vbCRLF & vbtab & "1) Defrag and consolidate the hard drive" & vbCRLF & vbtab _
        & "2) Image the system using DriveImageXML" & vbCRLF & vbCRLF _
        & vbCRLF & vbCRLF & vbCRLF & "Would you like to proceed with Archiving this system?",292,"Welcome to CAS")
        
if answer = vbNo then ' Answered no the question of if they want to proceed
    wscript.quit
end if

do while verify <> "6"    
    computerName = InputBox("Please enter the computer name for this system." & vbCRLF & vbCRLF _
        & "i.e. - TESTXP","COMPUTER NAME")

    verify = msgbox("Computer Name: " & UCase(computerName) & vbCRLF _
        & vbCRLF & vbCRLF & "Is this correct?",3,"Use these settings?")

    if verify = "2" then
        wscript.echo "Quiting CIS"
        wscript.quit
    end if
loop

shResult = objWshShell.Popup ("This is your last chance to stop the archiving if this machine's local drives!!" & vbCRLF _
    & vbCRLF & vbCRLF & vbTab _
    & "Timeout in 60 seconds",60,"Archive this system?",1)

if shResult = vbCancel then
    wscript.quit
end if

' \\ Checking to see if the computer has already been archived once.
' \\ Check to see if the current directory exists
' \\ -1 = exists    0 = doesn't exist
isFolder = objFSO.FolderExists(oldImagePath & CurrentYear & "\" & computerName)

if isFolder = 0 then
    set makeFolder = objFSO.CreateFolder(oldImagePath & CurrentYear & "\" & UCase(computerName))
    dirPath = oldImagePath & CurrentYear & "\" & computerName
else
    i = 1
    dirExists = "no"
    Do Until dirExists = "yes"
        isFolder = objFSO.FolderExists(oldImagePath & CurrentYear & "\" & computerName & i)
        if isFolder = 0 then
            set makeFolder = objFSO.CreateFolder(oldImagePath & CurrentYear & "\" & UCase(computerName & i))
            dirPath = oldImagePath & CurrentYear & "\" & computerName & i
            dirExists = "yes"
        else
            i = i + 1
        end if
    Loop
end if

' \\  Run DIRMS to consalidate & defrag all fixed hard drives.  
' \\  Then Image the drive using DriveImageXML
' //  NOTE:  Remove any mapped drives from the array below.  I use X, Y & Z for my mapped drives.  If you mape a network drive
' //    to any of the drives in the below array, it will image those drives.  That would not be good.
drvArray = array("C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:")
for each x in drvArray
    if objFSO.DriveExists(x) then
        set drvType = objFSO.GetDrive(x)
        if drvType.DriveType = "2" then
            ' \\ Deleting pagefile.sys if it exists.  
            isFile = objFSO.FileExists (x & "\pagefile.sys")

            if isFile = -1 then
                objFSO.DeleteFile x & "\pagefile.sys",True
            end if
            shResult = objWshShell.Run ("%comspec% /c " & dirmsPath & " " & x & " -q",1,True)
            shResult = objWshShell.Run ("%comspec% /c " & dirmsPath & " /b" & x & " /t" & dirPath & "\Drive_"  & Left(x,1) & " /s- /c /l",1,True)
        end if
    end if
next

' // This section will open up the drive C image on the local machine to make sure it s good and to let you know that it worked.
objWshShell.Run DIXMLPath
wscript.sleep 4000
objWshShell.SendKeys "%F"
wscript.sleep 600
objWshShell.SendKeys "O"
wscript.sleep 1500
objWshShell.SendKeys dirPath & "\Drive_c.xml"
wscript.sleep 600
objWshShell.SendKeys "{ENTER}"
wscript.sleep 600

wscript.echo "Image Complete.  Check the image to make sure it is complete!!"


Back to VBScript FAQ Index
Back to VBScript Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close