• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
<html><head><title>Inventory Computers</title><HTA:APPLICATIONID="objHTAInventory"APPLICATIONNAME="HTA_Inventory"SCROLL="yes"SINGLEINSTANCE="yes"WINDOWSTATE="normal"></head><SCRIPT Language="VBScript">'*******************************************************************************'Script to accept a text file as source of machine names, then create a new' Excel workbook for each computer in the file and save the workbook as the' computer name. Each workbook will contain a sheet for hardware, software,' printers, services, and general information.'Created by Brian Bohanon'Created: 7/7/2008'*******************************************************************************Option Explicit'Global VariablesDim arrFileLines()'array to hold computer namesDim tst'variable for fileDim i, j, k, l'global counters'ObjectsDim objFSO, objFile, objDialog, objExcel, objWMIService, objWorkbookDim objPrintItem, objDiskDrive, objExplorer, objLocalWMIService, objLocalItemDim objOSItem, objBIOS, objSetting, objQuickFix, objSoftware, objServiceDim objDrive, objNet, objProcItem, objSCSIItem, objVideo, objDisk'CollectionsDim colOSItems, colBIOS, colSettings, colQuickFixes, colSoftware, colServicesDim colPrintItems, colDisks, colDiskDrives, colDrives, colNet, colProcItemsDim colSCSIItems, colVideo, colLocalItemsDim WshShell'Provides access to WScript.ShellDim srcFileName'source fileDim intResult'used to test open file dialogDim strComputer'active computer to inventoryDim strDirectory'Local directoryDim strLocalComputer'Local computer script is running onDim intHorizontal, intVertical, intLeft, intTop'ConstantsConst xlLeft = -4131Const xlHorizontal = -4128'*******************************************************************************'Sub routines'*******************************************************************************Sub Window_onLoadSet WshShell = CreateObject("WScript.Shell")strLocalComputer = "."'Set current directory to Desktop & display on pagestrDirectory = WshShell.SpecialFolders("Desktop") & "\"DirectorySpan.innerhtml = "The files will be saved to " & strDirectory
 
'Set window sizewindow.resizeTo 550, 750 Set objLocalWMIService = GetObject("winmgmts:\\" & strLocalComputer &_ "\root\cimv2")Set colLocalItems = objLocalWMIService.ExecQuery("Select * From " &_ "Win32_DesktopMonitor") 'Compensation for multiple video adapters, i.e. laptopsFor Each objLocalItem in colLocalItemsIf intHorizontal <> "" ThenExit ForElse'get the current resolutionintHorizontal = objLocalItem.ScreenWidthintVertical = objLocalItem.ScreenHeightEnd IfNext'divide the center on the screenintLeft = (intHorizontal - 550) / 2intTop = (intVertical - 650) / 2window.moveTo intLeft, intTopSet objLocalWMIService = NothingSet objLocalItem = NothingSet WshShell = NothingEnd Sub'*******************************************************************************Sub CreateLog()On Error Resume NextDim objFileDim strFile, strText'Create log filestrFile = "InventoryLog_" & Month(Date()) & "_" & Day(Date()) & ".txt"Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.CreateTextFile(strDirectory & strFile)Set objFile = Nothing'Write headers to the log filestrText = "Computer Name,Date,Result,Return Code"Set objFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)objFile.WriteLine(strText)'Reset strText for later usestrText = ""Set objFSO = NothingSet objFile = NothingEnd Sub'*******************************************************************************
 
'Used to append the log for each computer the script is run againstSub WriteLog(strErrorNumber)On Error Resume NextDim objFile, objTextFileDim strFile, strTextstrFile = "InventoryLog_" & Month(Date()) & "_" & Day(Date()) & ".txt"Set objFSO = CreateObject("Scripting.FileSystemObject")'Check to see if the log existsIf objFSO.FileExists(strDirectory & strFile) Then'Write to the logSelect Case strErrorNumberCase 0' Success'strText = strComputer & "," & Date() & "," & "Success"Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)objTextFile.WriteLine(strText)objTextFile.CloseCase 70'' Run-time error '70': Permission denied'strText = strComputer & "," & Date() & "," & "Permission denied," &_ strErrorNumberSet objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)objTextFile.WriteLine(strText)objTextFile.Close'Case 462'' The remote server machine does not exist or is unavailable'strText = strComputer & "," & Date() & "," & "Machine does not exist or " &_ "is unavailable," & strErrorNumberSet objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)objTextFile.WriteLine(strText)objTextFile.Close'Case -2147217375'' Unknown/undocumented runtime error (till this time)' The remote server machine name was assigned erroneouslystrText = strComputer & "," & Date() & "," & "Unknown Error," & strErrorNumberSet objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)objTextFile.WriteLine(strText)objTextFile.Close'Case Else'
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...