Well after someone wrote and complained that the script did not work (turned out they had not installed the WinZip Command Line app as told to), and speaking with Lonkero about the archiving program I rewrote this script to take advantage of the archiving program 7-Zip.

You can download the full GUI version here. Welcome to the 7-Zip Home! another good change in this script is that 7-Zip reduces the overall size of the archive by almost 50% compared to using WinZip and it's FREE to use.

7-Zip is free software distributed under the GNU LGPL

This updated script now does the following:
  • Checks if user has Admin rights and quits if not
  • Checks if there is at least 125MB of free space and quits if not
  • Automatically creates the C:\7ZA\ folder and downloads the 7z command line program 7za415b.exe
  • Extracts the file 7za415b.exe to the C:\7ZA\ folder
  • Automatically creates the C:\BACKUP_SYSTEM\ folder
  • List all files on the system via DIR C:\ /S
  • Exports the entire Registry to a text file
  • Copies BOOT.INI, WIN.INI, SYSTEM.INI to the archive
  • List all running services
  • net statistics workstation
  • net statistics server
  • netstat -a Active Connections
  • netstat -r Routing Table
  • nbtstat -S Sessions
  • net config workstation
  • proxycfg WinHTTP Default Proxy
  • Uses 7z command line app with maximum compression and archives all files above into the archive
  • Alerts the user when there are more then 7 archive files in the folder.


You can use the GUI version of 7z to review the files within the archive. WinRAR can also open this file format.

NOTE: This script has only been tested with KiX32 v4.22 and Windows XP English w/SP2
It has not been tested on Windows 2000 yet, but it should work on 2000 as well.


Sample Output
  • Warning! Each run of this backup will temporarily consume up to 100MB of diskspace or more.
    Once completed the final size will be between 5 to 10MB of diskspace per run.
    You must decide how many versions to save and when to delete them yourself.

    Backup script start time: 03:21:54

    Please wait while we record a listing of all files on the system...
    Completed recording files and saved to: C:\BACKUP_SYSTEM\2005-03-25_03.21.54_FileListing.txt
    Please wait while we export the registry to: C:\BACKUP_SYSTEM\2005-03-25_03.21.54_RegistryBackup.txt
    Completed export of the registry
    Please wait while we copy other important files to: C:\BACKUP_SYSTEM\

    Completed copying files to C:\BACKUP_SYSTEM\
    Please wait while we archive all the backup files in C:\BACKUP_SYSTEM\


    7-Zip (A) 4.15 beta Copyright (c) 1999-2005 Igor Pavlov 2005-01-25
    Scanning

    Creating archive C:\BACKUP_SYSTEM\_SystemBackup.7z

    Compressing 2005-03-25_03.21.54_boot.ini
    Compressing 2005-03-25_03.21.54_system.ini
    Compressing 2005-03-25_03.21.54_win.ini
    Compressing 2005-03-25_03.21.54_ActiveConnections.txt
    Compressing 2005-03-25_03.21.54_DefaultProxy.txt
    Compressing 2005-03-25_03.21.54_FileListing.txt
    Compressing 2005-03-25_03.21.54_NetworkServerStats.txt
    Compressing 2005-03-25_03.21.54_NetworkWorkstationStats.txt
    Compressing 2005-03-25_03.21.54_RegistryBackup.txt
    Compressing 2005-03-25_03.21.54_RouteTable.txt
    Compressing 2005-03-25_03.21.54_RunningServices.txt
    Compressing 2005-03-25_03.21.54_Sessions.txt
    Compressing 2005-03-25_03.21.54_WorkStationConfig.txt

    Everything is Ok


    The backup file will be renamed once it reaches over 7 days old. Age of backup file 0

    Completed all backup routines.
    Backup script end time: 03:23:27
    Time to complete backup was: 93 seconds
    Size of backup archive file is: 3,187,429 bytes

    Press any key to end...


Break On
Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')


Dim $Folder, $File, $Reg, $Age, $Start, $Finish, $OrigAge, $Attrib
Dim $URL, $Target, $GetFile, $7zFolder, $Space, $Admin,$Archives
$Admin=IIf(InGroup(@WKSTA+'\'+SidToName('S-1-5-32-544'))-1+@INWIN=1,'Yes','No')
If $Admin='No'
? 'You must have local Admin rights to run this script...'
Quit 5
EndIf
$Space=GetDiskSpace('c:')
If $Space<'125000'
? 'System does not appear to have enough space to run the backup'
Quit 112
EndIf
$7zFolder='C:\7ZA\'
If Not GetFileAttr($7zFolder)=16
MD $7zFolder
If @ERROR ? 'Error creating '+ $7zFolder QUIT @ERROR EndIf
EndIf
$URL='http://www.kixhelp.com/Downloads/7za415b.exe'
$Target=$7zFolder+'7za415b.exe'
If GetFileVersion('C:\7ZA\7za.exe','BinFileVersion')<'4.15.0.0'
$GetFile=FTPget($URL, $Target)
If GetFileVersion($Target,'BinFileVersion')<'4.15.0.0'
? 'Error getting 7z file to create archives...'
Quit 3
Else
SHELL $Target + ' -y'
DEL $Target
EndIf
EndIf
$Folder='C:\BACKUP_SYSTEM\'
$File=Join(Split(@DATE,'/'),'-')+'_'+Join(Split(@TIME,':'),'.')
$Reg='_RegistryBackup.txt'
$Start=@TICKS
COLOR +W/R
'Warning! Each run of this backup will temporarily consume up to 100MB of diskspace or more.' ?
'Once completed the final size will be between 5 to 10MB of diskspace per run. ' ?
'You must decide how many versions to save and when to delete them yourself.' ??
COLOR +W/B
'Backup script start time: ' + @TIME ??
If Not GetFileAttr($Folder)=16
MD $Folder
If @ERROR ? 'Error creating '+ $Folder QUIT @ERROR EndIf
EndIf
$Archives = CountFiles($Folder,'*.7z') ; Check to see how many archive files exist
? 'There are ' + $Archives + ' archive files in the folder.' ?
If $Archives > 7 ; If more then 7 files exist then print out message
? 'Warning... There are now more then 7 archive files in the ' + $Folder + ' directory. '
? 'You should consider cleaning up or moving some to a CD or DVD' ?
EndIf
'Please wait while we record a listing of all files on the system...' ?
SHELL '%comspec% /c DIR C:\ /S >'+$Folder+$File+'_FileListing.txt'
SHELL '%comspec% /c net start >'+$Folder+$File+'_RunningServices.txt'
SHELL '%comspec% /c net statistics workstation >'+$Folder+$File+'_NetworkWorkstationStats.txt'
SHELL '%comspec% /c net statistics server >'+$Folder+$File+'_NetworkServerStats.txt'
SHELL '%comspec% /c netstat -a >'+$Folder+$File+'_ActiveConnections.txt'
SHELL '%comspec% /c netstat -r >'+$Folder+$File+'_RouteTable.txt'
SHELL '%comspec% /c nbtstat -S >'+$Folder+$File+'_Sessions.txt'
SHELL '%comspec% /c proxycfg >'+$Folder+$File+'_DefaultProxy.txt'
SHELL '%comspec% /c net config workstation >'+$Folder+$File+'_WorkStationConfig.txt'
'Completed recording files and saved to: ' + $Folder+$File+'_FileListing.txt' ?
'Please wait while we export the registry to: ' + $Folder+$File+$Reg ?
SHELL 'regedit.exe /e ' + $Folder+$File+$Reg
SHELL 'regedit /e ' + $Folder+$File+'_HKLM_RUN.txt ' +'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
SHELL 'regedit /e ' + $Folder+$File+'_HKCU_RUN.txt ' +'HKCU\Software\Microsoft\Windows\CurrentVersion\Run'
'Completed export of the registry' ?
'Please wait while we copy other important files to: ' + $Folder ??
COPY '%WINDIR%\win.ini' $Folder+$File+'_win.ini'
COPY '%WINDIR%\system.ini' $Folder+$File+'_system.ini'
$Attrib=SetFileAttr('C:\boot.ini',128)
COPY 'C:\boot.ini' $Folder+$File+'_boot.ini'
$Attrib=SetFileAttr('C:\boot.ini',7)
'Completed copying files to ' $Folder ?
'Please wait while we archive all the backup files in ' + $Folder ??
SHELL 'C:\7ZA\7za.exe'+' a -t7z '+$Folder+$File+'_SystemBackup.7z '+$Folder+'*.txt '+$Folder+'*.ini'+' -mx9'
DEL $Folder+'*.txt'
DEL $Folder+'*.ini' /c /f /h
$Finish=(@TICKS-$Start)
COLOR +W/B
'Completed all backup routines.' ?
'Backup script end time: ' + @TIME ?
'Time to complete backup was: ' + ($Finish/1000) + ' seconds' ?
'Size of backup archive file is: ' + FormatNumber(GetFileSize($Folder+$File+'_SystemBackup.7z'),0,,,-2)+' bytes' ??
COLOR +R/W
'Press any key to end...' ?
Get $Pause
Quit 1


Function CountFiles($Folder,$Type)
Dim $Index,$File
$Index = 0
$File = Dir($Folder+'\'+$Type)
While @ERROR = 0
If Not (GetFileAttr($File) & 16)
$Index = $Index + 1
EndIf
$File = Dir()
Loop
$CountFiles=$Index
EndFunction


Function DateCalc($date1, $DateOrMod, optional $SingleDigit)
Dim $_intDate1,$_intYear1,$_intMonth1,$_intDay1
Dim $_intDate2,$_intYear2,$_intMonth2,$_intDay2
$date1=Split($date1,'/')
If UBound($date1)<>2
Exit 1
EndIf
$_intYear1 = Val($date1[0])
$_intMonth1 = Val($date1[1])
$_intDay1 = Val($date1[2])
If $_intMonth1 < 3
$_intMonth1 = $_intMonth1 + 12
$_intYear1 = $_intYear1 - 1
EndIf
$_intDate1=$_intDay1+(153*$_intMonth1-457)/5+365*$_intYear1 +
$_intYear1/4-$_intYear1/100+$_intYear1/400-306
Select
Case VarType($DateOrMod)=3
$_intDate2=$_intDate1+$DateOrMod
If InStr($_intDate2,'-')$_intDate2=Val(SubStr($_intDate2,2,len($_intDate2)-1)) EndIf
$_intYear2=(100*(((100*($_intDate2+306)-25)/3652425)-(((100*($_intDate2+306)-25)/3652425)/4))
+(100*($_intDate2+306)-25))/36525
$_intMonth2=(5*(((100*($_intDate2+306)-25)/3652425)-(((100*($_intDate2+306)-25)/3652425)/4)
+($_intDate2+306)-365*$_intYear2-$_intYear2/4)+456)/153
$_intDay2=(((100*($_intDate2+306)-25)/3652425)-(((100*($_intDate2+306)-25)/3652425)/4)
+($_intDate2+306)-365*$_intYear2-$_intYear2/4)-(153*$_intMonth2-457)/5
If $_intMonth2 > 12 $_intYear2=$_intYear2+1 $_intMonth2=$_intMonth2-12 EndIf
If Not $SingleDigit
If Len($_intYear2)< 4
$_=Execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next")
EndIf
$_intMonth2=Right("0" + $_intMonth2,2)
$_intDay2=Right("0" + $_intDay2,2)
EndIf
$DateCalc=$_intYear2+'/'+$_intMonth2+'/'+$_intDay2
Case VarType($DateOrMod)=8
$DateOrMod=Split($DateOrMod,'/')
If UBound($DateOrMod)<>2
Exit 1
EndIf
$_intYear2 = Val($DateOrMod[0])
$_intMonth2 = Val($DateOrMod[1])
$_intDay2 = Val($DateOrMod[2])
If $_intMonth2 < 3
$_intMonth2 = $_intMonth2+12
$_intYear2 = $_intYear2-1
EndIf
$_intDate2=$_intDay2+(153*$_intMonth2-457)/5+365*$_intYear2 +
$_intYear2/4-$_intYear2/100+$_intYear2/400-306
$DateCalc=$_intDate1-$_intDate2
;comment the next line if you wish to return negative results also !!!
If InStr($DateCalc,'-') $DateCalc = Val(SubStr($DateCalc,2,Len($DateCalc)-1)) EndIf
Case 1
Exit 1
EndSelect
EndFunction




Function FTPget($sURL, $sTargetFile, optional $sUser, optional $sPass)
Dim $oFTP, $oStream
$sUser=""+$sUser
$oFTP = CreateObject("Microsoft.XMLHTTP")
if @error $ftpget=1 exit 1 endif
$oStream = CreateObject("ADODB.Stream")
if @error $ftpget=2 exit 2 endif
if $sUser
$oFTP.Open("GET", $sURL, not 1, $sUser, $sPass)
else
$oFTP.Open("GET", $sURL, not 1)
endif
if @error $ftpget=3 exit 3 endif
$oFTP.Send
$oStream.Type = 1
$oStream.Mode = 3
$oStream.open
$oStream.Write($oFTP.responseBody)
if @error $ftpget=4 exit 4 endif
$oStream.SaveToFile($sTargetFile, 2)
if @error $ftpget=5 exit 5 endif
$oStream.Close
EndFunction




Edited by NTDOC (2005-04-05 02:39 AM)