'~~[author]~~ 'Carl Taylor '~~[/author]~~ '~~[emailAddress]~~ 'carl_g_taylor@hotmail.com '~~[/emailAddress]~~ '~~[scriptType]~~ 'vbscript '~~[/scriptType]~~ '~~[subType]~~ 'SystemAdministration '~~[/subType]~~ '~~[keywords]~~ 'logon script, inventory, access, auditing '~~[/keywords]~~ '~~[comment]~~ 'The script is designed to run as part of a logon script and keep upto date hardware & some software item inventory records of the computers logging onto the network. It is a long promised update to my previous inventory script. '~~[/comment]~~ '~~[script]~~ ' Written by: Carl Taylor ' E-mail: carl_g_taylor@hotmail.com ' Date: 26th May 2004 ' ' Comments: This script is designed to be run from a logon script and enter details into an access database. ' Datasource need to be changed to reflect location and name of database. Logon script runs this ' Once per reporting period. Reporting period is defined in CMD or Batch file. ' ' Acknowledgements: Microsoft Scripting Guys webcasts, website & Windows 2000 Scripting guide ' Win32 Scripting Website @ http://cwashington.netreach.net ' All VBS Scriptors Who helped whilst learning ' ' ' Database Fields: ComputerName Text 255 ' Model Text 255 ' Vendor Text 255 ' Serial Text 255 ' Version Text 255 ' CPU Text 255 ' Speed Text 255 ' MonitorManufacturer Text 255 ' MonitorModel Text 255 ' VideoRAM Number Long Integer ' VideoCard Text 255 ' VideoMode Text 255 ' OS Text 255 ' SP Text 255 ' Asset Text 255 ' CDrive Text 255 ' CFreeSpace Number Long Integer ' CTotalSpace Number Long Integer ' DDrive Text 255 ' DFreeSpace Number Long Integer ' DTotalSpace Number Long Integer ' CD Text 255 ' CDDescription Text 255 ' RAM Number Long Integer ' NetworkCard Text 255 ' MAC Text 255 ' User Text 255 ' Date Date/Time Short Date ' Time Date/Time Medium Time ' ********** Global Declarations ********** Dim strComputerName ' The Computer Name to be queried via WMI Dim strWinMgt ' The WMI management String Dim objCon ' A Connection Object for database connectivity Dim objRS ' A Recordset Object for database connectivity Dim sProviderName ' The OLE Provider Type Dim iCursorType ' The Cursor Type for the Recordset Dim iLockType ' The Lock Type for the Recordset Dim sDataSource ' The name and location of the database Dim intRam ' The amount of RAM in the computer. Dim CompSysSet Dim CompSys strComputerName = "." strWinMgt = "winmgmts://" & strComputerName &"" '********** Beginning of Main Code ********** ' Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem") For Each CompSys In CompSysSet strName = CompSys.Name Next Call subConnectionOpen strCriteria = "ComputerName = '"& strName &"'" objRS.Find strCriteria If objRS.EOF Then Call subGetComputerInfo Else Call subDeleteRecord Call SubGetComputerInfo End If Call subConnectionClose '********** End of Main Code ********** '********** Beginning of Sub routine to Open database ********** Sub subConnectionOpen Set objCon = CreateObject("ADODB.Connection") Set objRS = CreateObject("ADODB.Recordset") sProviderName = "Microsoft.Jet.OLEDB.4.0" iCursorType = 1 iLockType = 3 sDataSource = "pcinfo.mdb" objCon.Provider = sProviderName objCon.Properties("Data Source") = sDataSource objCon.Open objRS.CursorType = iCursorType objRS.LockType = iLockType objRS.Source = "Computerinfo" objRS.ActiveConnection = objCon objRS.Open End Sub '********** End of sub routine to Open database ********** '********** Beginning of Sub routine to Close database ********** Sub subConnectionClose Set objRS = Nothing Set objCon = Nothing End Sub '********** End of Sub routine to Close database ********** '********** Beginning of Sub routine to delete record ********** Sub subDeleteRecord objRS.Delete objRS.Update End Sub '********** End of Sub routine to delete record ********** '********** Beginning of Sub routine to get & write computer info ********** Sub subGetComputerInfo ' Get Model, Manufacturer, Computername and Memory Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem") For Each CompSys In CompSysSet strModel = CompSys.Model ComputerName = CompSys.Name strVendor = CompSys.Manufacturer intRAM = Clng(CompSys.TotalPhysicalMemory/1048576 ) Next ' Get BIOS info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_BIOS") For Each CompSys In CompSysSet strSerial = CompSys.SerialNumber strVersion = CompSys.Version Next ' Get CPU info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_Processor") For Each CompSys In CompSysSet strCPU = CompSys.Name ' StrSpeed = CompSys.CurrentClockSpeed StrSpeed = CompSys.MaxClockSpeed Next ' Get Monitor Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_DesktopMonitor") For Each CompSys In CompSysSet strMonManufacturer = CompSys.MonitorManufacturer strMonModel = CompSys.Description Next ' Get Video Card Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_VideoController") For Each CompSys In CompSysSet strVidRAM = CompSys.AdapterRAM/1024 strVidCard = CompSys.Description strVidMode = CompSys.VideoModeDescription Next ' Get OS Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_OperatingSystem") For Each CompSys In CompSysSet strOS = CompSys.Caption strSP = CompSys.CSDVersion Next ' Get Asset Tag Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_SystemEnclosure") For Each CompSys In CompSysSet strAsset = CompSys.SMBIOSAssetTag Next ' Get Disk Information for C drive ' Set DiskSet = GetObject(strWinMgt).ExecQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DeviceID = 'C:' and DriveType=3") For Each Disk In DiskSet Rem strDisplayDiskInfo = strDisplayDiskInfo & "Drive " & Disk.Name & " Free Space: " & Clng(Disk.FreeSpace/1000000) & " MB Total Size: " & Clng(Disk.Size/1000000) & " MB"& vbCrlf strCDriveLetter = Left(disk.name,2) strCFreeSpace = Disk.FreeSpace/2^30 strCTotalSpace = Disk.Size/2^30 Next ' Get Disk Information for D drive ' Set DiskSet = GetObject(strWinMgt).ExecQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DeviceID = 'D:' and DriveType=3") For Each Disk In DiskSet Rem strDisplayDiskInfo = strDisplayDiskInfo & "Drive " & Disk.Name & " Free Space: " & Clng(Disk.FreeSpace/1000000) & " MB Total Size: " & Clng(Disk.Size/1000000) & " MB"& vbCrlf strDDriveLetter = Left(disk.name,2) strDFreeSpace = Disk.FreeSpace/2^30 strDTotalSpace = Disk.Size/2^30 Next ' Get Network Card Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled = 'TRUE'") For Each CompSys In CompSysSet strMAC = CompSys.MACAddress strNICModel = CompSys.Description Next ' Get User Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem") For Each CompSys In CompSysSet strUser = CompSys.UserName Next ' Get CD Info Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_CDROMDrive") For Each CompSys In CompSysSet strCD = CompSys.Drive strCDDescription = CompSys.Name Next objRS.AddNew objRS("ComputerName") = strName objRS("Model") = strModel objRS("Vendor") = strVendor objRS("Serial") = strSerial objRS("Version") = strVersion objRS("CPU") = strCPU objRS("Speed") = strSpeed objRS("MonitorManufacturer") = strMonManufacturer objRS("MonitorModel") = strMonModel objRS("VideoRAM") = strVidRAM/1024 objRS("VideoCard") = strVidCard objRS("VideoMode") = strVidMode objRS("OS") = strOS objRS("SP") = strSP objRS("Asset") = strAsset objRS("CDrive") = strCDriveLetter objRS("CFreeSpace") = strCFreeSpace objRS("CTotalSpace") = strCTotalSpace objRS("DDrive") = strDDriveLetter objRS("DFreeSpace") = strDFreeSpace objRS("DTotalSpace") = strDTotalSpace objRS("CD") = strCD objRS("CDDescription") = strCDDescription objRS("RAM") = intRAM objRS("NetworkCard") = strNICModel objRS("MAC") = strMAC objRS("User") = strUser objRS("Date") = Date() objRS("Time") = Time() objRS.Update objRS.Close End Sub '********** End of Sub routine to get & write computer info ********** '***************************************************************************************** '~~[/script]~~