#include <Array.au3>
#NoTrayIcon
;AutoItSetOption("MustDeclareVars", 1)
Dim $INI
Dim $INI_RunApplications, $INI_RunPrinters, $INI_RunDrives, $INI_RunBackup, $INI_RunNetwork
Dim $INI_FileInventory, $INI_FileBKSFile, $INI_FileBKFFile, $INI_FileBackupLogs
Dim $INI_ExitLetter, $INI_ExitFile
Dim $INI_ExcludeAppsDisp[100]
Dim $INI_ExcludeAppsPub[100]
Dim $INI_SortDisplayName, $INI_SortPublisher, $INI_SortDescending
Dim $INI_CommentsApps[3]
Dim $INI_CommentsPrint[3]
Dim $INI_CommentsDrives[3]
Dim $INI_CommentsNetwork[3]
Dim $INI_BackStartMsgLine[10], $INI_BackEndMsgLine[10]
Dim $INI_BackStartMsgEnabled, $INI_BackStartMsgCloseDelay, $INI_BackEndMsgEnabled, $INI_BackEndMsgCloseDelay
Dim $INI_BackupLogType, $key, $INI_BackupHide
Dim $DisplayName
Dim $Publisher
Dim $AppIncrement ;Array increment to be used as a counter and argument passed to the AppWrite function.
Dim $A_Apps[1000] ;Array to be used for collection of data
Dim $A_Prn[25]
Dim $A_Drv[25]
$ObjNet = ObjCreate("WScript.NetWork")
$INI = $CmdLine[$CmdLine[0]]
If $INI = "" Then $INI = "Inventory.ini"
If FileExists($INI) = 0 Then Exit
Call ("INI_Load")
FileDelete ($INI_FileInventory)
FileOpen ($INI_FileInventory, 10)
If $INI_RunApplications =1 then Call("Applications")
If $INI_RunPrinters = 1 Then Call("Printers")
If $INI_RunDrives = 1 then call("Drives")
If $INI_RunNetwork = 1 Then call ("Network")
If $INI_RunBackup = 1 Then call ("Backup")
FileClose ($INI_FileInventory) ;Close the Inventory file.
Func INI_Load() ;INI Load
;SECTIONS_TO_RUN
$INI_RunApplications = IniRead($INI, "SECTIONS_TO_RUN", "Applications",1)
$INI_RunPrinters = IniRead($INI, "SECTIONS_TO_RUN", "Printers",1)
$INI_RunDrives = IniRead($INI, "SECTIONS_TO_RUN", "Drives",1)
$INI_RunNetwork = IniRead($INI, "SECTIONS_TO_RUN", "Network",1)
$INI_RunBackup = IniRead($INI, "SECTIONS_TO_RUN", "Backup",1)
;FILE
$INI_FileInventory = IniRead($INI, "FILE", "Inventory","") & "\" & @UserName & "\inventory.txt"
$INI_FileBKSFile = IniRead($INI, "FILE", "BKSFile", "backup.bks")
$INI_FileBKFFile = IniRead($INI, "FILE", "BKFFile", "inventory.bkf")
$INI_FileBackupLogs = IniRead($INI,"FILE", "BackupLogs",0)
;EXIT_ON_COMPUTERNAME
For $i = 1 to StringLen(@Computername)
$INI_ExitLetter = IniRead($INI, "EXIT_ON_COMPUTERNAME", "Letter" & $i,"")
If $INI_ExitLetter <> "" and $INI_ExitLetter = StringMid (@Computername, $i,1) Then Exit
Next
;EXIT_ON_PRESENT_FILE
For $i = 1 to 5
$INI_ExitFile = IniRead($INI, "EXIT_ON_PRESENT_FILE", "File" & $i, "")
If $INI_ExitFile <> "" and FileExists($INI_ExitFile) Then Exit
Next
;EXCLUDE_APPLICATIONS
for $i = 1 to 100
if IniRead($INI, "EXCLUDE_APPLICATIONS", "DisplayName" & $i,"") <> "" then _ArrayAdd ($INI_ExcludeAppsDisp, IniRead($INI, "EXCLUDE_APPLICATIONS", "DisplayName" & $i,""))
if IniRead($INI, "EXCLUDE_APPLICATIONS", "Publisher" & $i,"") <> "" then _ArrayAdd ($INI_ExcludeAppsPub, IniRead($INI, "EXCLUDE_APPLICATIONS", "Publisher" & $i,""))
Next
_ArraySort($INI_ExcludeAppsDisp)
_ArraySort($INI_ExcludeAppsPub)
;COMMENTS
For $i = 1 to 3
_ArrayInsert($INI_CommentsApps, $i, IniRead($INI, "COMMENTS", "Applications" & $i, "*****Applications*****"))
_ArrayInsert ($INI_CommentsPrint, $i, IniRead ($INI, "COMMENTS", "Printers" & $i, "*****Printers*****"))
_ArrayInsert ($INI_CommentsDrives, $i, IniRead ($INI, "COMMENTS", "Drives" & $i, "*****Drives*****"))
_ArrayInsert ($INI_CommentsNetwork, $i, IniRead ($INI, "COMMENTS", "Network" & $i, "*****Network Info*****"))
Next
;BACKUP START/END MESSAGE
$INI_BackStartMsgEnabled = IniRead($INI, "BACKUP_START_MESSAGE", "Enabled", 0)
$INI_BackStartMsgCloseDelay = IniRead($INI, "BACKUP_START_MESSAGE", "CloseDelay", 20)
$INI_BackEndMsgEnabled = IniRead($INI, "BACKUP_END_MESSAGE", "Enabled", 0)
$INI_BackEndMsgCloseDelay = IniRead($INI, "BACKUP_END_MESSAGE", "CloseDelay", 20)
For $i = 1 to 10
_ArrayInsert ($INI_BackStartMsgLine, $i, IniRead($INI, "BACKUP_START_MESSAGE", "Line" & $i, ""))
_ArrayInsert ($INI_BackEndMsgLine, $i, IniRead($INI, "BACKUP_END_MESSAGE", "Line" & $i, ""))
Next
;BACKUP
$INI_BackupLogType = IniRead($INI, "BACKUP", "BackupLogType", "F")
$INI_BackupHide = IniRead($INI, "BACKUP", "BackupHide", 1)
EndFunc
Func Applications() ;--------------------Applications--------------------
Filewrite ($INI_FileInventory, @CRLF)
For $i = 1 to 3
FileWrite ($INI_FileInventory, $INI_CommentsApps[$i] & @CRLF)
Next
FileWrite ($INI_FileInventory, "DisplayName" & @TAB & "Publisher" & @CRLF)
FileWrite ($INI_FileInventory, "----------" & @TAB & "----------" & @CRLF)
;Enumerate applitions under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall key in the registry. Up to 1000 keys.
For $AppIncrement = 1 to 1000
$key = RegEnumKey ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", $AppIncrement)
if @error <> 0 then ExitLoop
$DisplayName = RegRead ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $key, "DisplayName")
$Publisher = RegRead ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $key, "Publisher")
If $DisplayName <> $Publisher and $DisplayName <> "" Then
_ArrayInsert ($A_Apps, $AppIncrement, $DisplayName & @TAB & $Publisher & @CRLF)
EndIf
Sleep(10)
Next
_ArraySort ($A_Apps,0,0,1000) ;Sort the array by $DisplayName, or whatever the first variable value in the begging of the line is. - INI
for $i = 1 to UBound($INI_ExcludeAppsDisp,1)-1
$Pos = _ArraySearch ($A_Apps,$INI_ExcludeAppsDisp[$i],0,0,0,true)
if $Pos <> -1 then
_ArrayDelete($A_Apps, $Pos)
$i = $i - 1
EndIf
Next
_ArraySort($A_Apps)
for $i = 1 to UBound($INI_ExcludeAppsPub,1)-1
$Pos = _ArraySearch ($A_Apps,$INI_ExcludeAppsPub[$i],0,0,0,true)
if $Pos <> -1 then
_ArrayDelete($A_Apps, $Pos)
MsgBox(0,$INI_ExcludeAppsPub[$i],$Pos)
$i = $i - 1
EndIf
Next
_ArraySort ($A_Apps,0,0,1000)
FileWrite($INI_FileInventory, _ArrayToString($A_Apps, "", 0, UBound($A_Apps,1) -1)) ;Convert the $A_apps array to a string and write the contents to a file.
EndFunc
func Printers()
Filewrite ($INI_FileInventory, @CRLF)
For $i = 1 to 3
FileWrite ($INI_FileInventory, $INI_CommentsPrint[$i] & @CRLF)
Next
$ObjPrn = $ObjNet.EnumPrinterConnections
FileWrite ($INI_FileInventory, "Port" & @TAB & "Printer" & @CRLF)
FileWrite ($INI_FileInventory, "----------" & @TAB & "----------" & @CRLF)
For $i = 0 to $ObjPrn.Count -1
_ArrayInsert($A_Prn, $i, $ObjPrn.Item($i))
Next
For $i = 0 to 25
If $A_Prn[$i] = "" then ExitLoop
FileWrite ($INI_FileInventory, $A_Prn[$i] & @TAB & $A_Prn[$i + 1] & @CRLF)
$i = $i + 1
Next
EndFunc
Func Drives()
Filewrite ($INI_FileInventory, @CRLF)
For $i = 1 to 3
FileWrite ($INI_FileInventory, $INI_CommentsDrives[$i] & @CRLF)
Next
$ObjDrv = $ObjNet.EnumNetworkDrives
FileWrite ($INI_FileInventory, "Drive" & @TAB & "Path" & @CRLF)
FileWrite ($INI_FileInventory, "----------" & @TAB & "----------" & @CRLF)
For $i = 0 to $ObjDrv.Count -1
_ArrayInsert ($A_Drv, $i, $ObjDrv.Item($i))
Next
For $i = 0 to 25
If $A_Drv[$i] = "" then ExitLoop
FileWrite ($INI_FileInventory, $A_Drv[$i] & @TAB & $A_Drv[$i + 1] & @CRLF)
$i = $i + 1
Next
EndFunc
Func Network()
Filewrite ($INI_FileInventory, @CRLF)
For $i = 1 to 3
FileWrite ($INI_FileInventory, $INI_CommentsNetwork[$i] & @CRLF)
Next
FileWrite ($INI_FileInventory, "Computer Name: " & @Tab & @ComputerName & @CRLF)
FileWrite ($INI_FileInventory, "Username: " & @TAB & @UserName& @CRLF)
FileWrite ($INI_FileInventory, "Operating System: " & @TAB & @OSVersion & " / " & @OSServicePack & @CRLF)
$strComputer = "."
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$nics = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For $nic in $nics
FileWrite ($INI_FileInventory, "Description:" & @TAB & $nic.Description & @CRLF)
if $nic.DHCPEnabled = True then FileWrite ($INI_FileInventory, "DHCP Enabled" & @CRLF)
For $i = 0 To UBound($nics) ;log IP/SubnetMask
if $nic.IPAddress($i) <> 0 Then FileWrite ($INI_FileInventory, "IPAddress" & $i & ":" & @TAB & $nic.IPAddress($i) & "/" & $nic.IPSubnet($i) & @CRLF)
If $nic.DefaultIPGateway($i) <> 0 then FileWrite ($INI_FileInventory, "Gateway" & $i & ":" & @TAB & $nic.DefaultIPGateway($i) & @CRLF)
If $nic.DNSServerSearchOrder($i) <> 0 then FileWrite ($INI_FileInventory, "DNS" & $i & ":" & @TAB & $nic.DNSServerSearchOrder($i) & @CRLF)
Next
FileWrite ($INI_FileInventory, @CRLF)
Next
EndFunc
Func Backup()
if $INI_BackStartMsgEnabled <> 0 Then MsgBox (262144,"PLEASE READ", _ArrayToString($INI_BackStartMsgLine, @CRLF), $INI_BackStartMsgCloseDelay)
$NTBACKUP = 'ntbackup.exe' & ' backup "@' & $INI_FileBKSFile & '" /j "Backup" /f "' & $INI_FileBKFFile & "\" & @username & '\Backup.bkf" /A /V:yes /L:' & $INI_BackupLogType & ' /M normal /SNAP:off'
;hide the backup utility
Select
Case $INI_BackupHide = 1
Run ($NTBACKUP , @SystemDir);run the backup utility
for $i = 1 to 60
WinSetState ("Backup Progress", "", @SW_HIDE)
WinSetState ("Backup Utility - [Untitled]", "", @SW_HIDE)
WinSetState ("Selection Information", "", @SW_HIDE)
$i = $i + 1
sleep (1000)
next
Case $INI_BackupHide = 0
RunWait ($NTBACKUP , @SystemDir);run the backup utility
EndSelect
$BackupState = WinGetState ("Backup Progress", "")
$BackupUtility = WinGetState ("Backup Utility - [Untitled]")
;check if the backup is running
While $BackupState <> 0
;& $BackupUtility <> 0
Sleep (10000)
$BackupState = WinGetState ("Backup Progress", "")
$BackupUtility = WinGetState ("Backup Utility - [Untitled]")
WEnd
;Copy over the backup logs
FileCopy ('c:\Documents and Settings\' & @UserName & '\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\*.*', $INI_FileBackupLogs & "\" & @UserName)
if $INI_BackEndMsgEnabled <> 0 Then MsgBox(262144,"BACKUP COMPLETE", _ArrayToString($INI_BackEndMsgLine, @CRLF), $INI_BackEndMsgCloseDelay)
EndFunc