Startup script that can get the hardware details of a machine and store in seperate txt files with machinename and date.

bsharath
bsharath used Ask the Experts™
on
Hi,

Startup script that can get the hardware details of a machine and store in seperate txt files with machinename and date.
On each startup the txt files should be created newly not overitten. So when some hardware is missing or changed. I know which date and between what time this has happened.
txt files should save as
Machinename_DD-MM-YYYY-1
Machinename_DD-MM-YYYY-2
and so on

Format of the harware has to look as

Processor/Ram/Hdd1/Hdd 2/Floppy/Cd/Mac Address/Total Slots/Free Slots/Bank 1/Bank 2/Bank 3/Bank 4

Can anyone help with a code as this please

Regards
sharath
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/computermanagement/hardware/
Great script and get hardware info. Instead of echoing it, just Writeline it into a log file.

Let me know if you want a sample script.

Author

Commented:
Can you help with combining them to just the format i want
No problem. What detail do you want. When you say HDD1 do you want the model or size or just the fact that it's there? Processor, just the name or the clock speed?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Author

Commented:
I want to know how many hardisks are there. and what size
Like
Processor/Ram/Hdd1/Hdd 2/Floppy/Cd/Mac Address/Total Slots/Free Slots/Bank 1/Bank 2/Bank 3/Bank 4
p4 3.2 core 2 duo\3 Gb\80Gb\40Gb\FDD\CDD\00-12-90-26-09-b5/4/2/2 Gb/1Gb/0/0
let me know....
'Get Computer Hardware and store into a local file
' Assumes logfiles are to be kept in the root of C
 
On Error Resume Next
 
Dim objFSO, objLog, strLogFile, strComputerName, strDate, strHardware, iCount, aryRam  
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
 
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
 
strDate = Right("0" & Day(Date), 2) & "-" & Right("0" & Month(Date),2) & "-" & Year(Date)
 
 
icount = 1
 
Do Until iCount = 255
	strLogFile = "C:\" & strComputerName & "_" & strDate & "-" & icount & ".txt"
	If objFSO.FileExists( strLogFile ) Then 
		iCount = iCount + 1
	Else
		exit Do
	End If
Loop
 
' If we have more than 255 maybe do some cleanup or something and start over with logfiles
' Call LogFileCleanup
' strLogFile ="C:\" & strComputerName & "_" & strDate & "-1" & ".txt"
 
Set objLog = objFSO.OpenTextFile( strLogFile, 2, True)
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_Processor")
	strHardware = procItem.Name & "\"
Next
 
For Each procItem In GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
	strHardware = strHardware & Round(procItem.TotalPhysicalMemory / 1048576, 0) & " MB\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_DiskDrive")
	strHardware = strHardware & Round(procItem.Size / 1073741824, 0) & "GB\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_FloppyDrive")
	strHardware = strHardware & procItem.Caption & "\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_CDRomDrive")
	strHardware = strHardware & procItem.Caption & "\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
	If procItem.IPEnabled = True Then
		strHardware = strHardware & procItem.MACAddress & "\"
	End If	
Next
 
iCount = 0
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	iCount = iCount + 1
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemoryArray")
	strHardware = strHardware & procItem.MemoryDevices & "\" & procItem.MemoryDevices - iCount & "\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	strHardware = strHardware & Round(procItem.Capacity / 1048576, 0) & " MB\"
Next
 
objLog.WriteLine strHardware
 
'Remove this line if you don't want confirmation that its done
MsgBox "All Done"

Open in new window

Author

Commented:
Thanks its perfect
Can i get NO if there is no FDD and CDD and also save the files in a UNC path.
I will use it as a startup script
here it is. uncomment the strlogpath variable you want and change as needed
'Get Computer Hardware and store into a local file
 
On Error Resume Next
 
Dim objFSO, objLog, strLogFile, strLogPAth, strComputerName, strDate, strHardware, strtmp, iCount, bHadDrive  
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
 
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
'strLogPath = "\\Servername\Serverfolder\"
'strLogPath = "C:\"
 
strDate = Right("0" & Day(Date), 2) & "-" & Right("0" & Month(Date),2) & "-" & Year(Date)
 
 
icount = 1
 
Do Until iCount = 255
	strLogFile = strLogPath & strComputerName & "_" & strDate & "-" & icount & ".txt"
	If objFSO.FileExists( strLogFile ) Then 
		iCount = iCount + 1
	Else
		exit Do
	End If
Loop
 
' If we have more than 255 maybe do some cleanup or something and start over with logfiles
' Call LogFileCleanup
' strLogFile = strLogPath & strComputerName & "_" & strDate & "-1" & ".txt"
 
Set objLog = objFSO.OpenTextFile( strLogFile, 2, True)
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_Processor")
	strHardware = procItem.Name & "\"
Next
 
For Each procItem In GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
	strHardware = strHardware & Round(procItem.TotalPhysicalMemory / 1048576, 0) & " MB\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_DiskDrive")
	strHardware = strHardware & Round(procItem.Size / 1073741824, 0) & "GB\"
Next
 
bHadDrive = FALSE
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_FloppyDrive")
	strHardware = strHardware & procItem.Caption & "\"
	bHadDrive = TRUE
Next
 
If bHadDrive = FALSE Then
	strHardware = strHardware & "NO FLOPPY\"
End If
 
bHadDrive = FALSE
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_CDRomDrive")
	strHardware = strHardware & procItem.Caption & "\"
	bHadDrive = TRUE
Next
 
If bHadDrive = FALSE Then
	strHardware = strHardware & "NO CD/DVD DRIVES\"
End If
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
	If procItem.IPEnabled = True Then
		strHardware = strHardware & procItem.MACAddress & "\"
	End If	
Next
 
iCount = 0
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	iCount = iCount + 1
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemoryArray")
	strHardware = strHardware & procItem.MemoryDevices & "\" & procItem.MemoryDevices - iCount & "\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	strHardware = strHardware & Round(procItem.Capacity / 1048576, 0) & " MB\"
Next
 
objLog.WriteLine strHardware
 
'Remove this line if you don't want confirmation that its done
MsgBox "All Done"

Open in new window

Author

Commented:
Thank u checking on this
Can you help on this too
http://www.experts-exchange.com/Programming/Languages/Q_24834981.html

Author

Commented:
I get this

Intel(R) Pentium(R) III Xeon processor\4095 MB\546GB\NO FLOPPY\00:1A:64:C7:DE\00:1A:64::DC\12\10\2048 MB\2048 MB\

I dont get the CDD
not sure...it tests out fine on 2 different systems here. Can you run this on the system and post me the output.
On Error Resume Next
 
Dim objFSO, objLog
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
Set objLog = objFSO.OpenTextFile( "C:\CDROM-Info.txt", 2, True)
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive",,48)
For Each objItem in colItems
    objLog.WriteLine "Availability: " & objItem.Availability
    objLog.WriteLine "Capabilities: " & objItem.Capabilities
    objLog.WriteLine "CapabilityDescriptions: " & objItem.CapabilityDescriptions
    objLog.WriteLine "Caption: " & objItem.Caption
    objLog.WriteLine "CompressionMethod: " & objItem.CompressionMethod
    objLog.WriteLine "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
    objLog.WriteLine "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
    objLog.WriteLine "CreationClassName: " & objItem.CreationClassName
    objLog.WriteLine "DefaultBlockSize: " & objItem.DefaultBlockSize
    objLog.WriteLine "Description: " & objItem.Description
    objLog.WriteLine "DeviceID: " & objItem.DeviceID
    objLog.WriteLine "Drive: " & objItem.Drive
    objLog.WriteLine "DriveIntegrity: " & objItem.DriveIntegrity
    objLog.WriteLine "ErrorCleared: " & objItem.ErrorCleared
    objLog.WriteLine "ErrorDescription: " & objItem.ErrorDescription
    objLog.WriteLine "ErrorMethodology: " & objItem.ErrorMethodology
    objLog.WriteLine "FileSystemFlags: " & objItem.FileSystemFlags
    objLog.WriteLine "FileSystemFlagsEx: " & objItem.FileSystemFlagsEx
    objLog.WriteLine "Id: " & objItem.Id
    objLog.WriteLine "InstallDate: " & objItem.InstallDate
    objLog.WriteLine "LastErrorCode: " & objItem.LastErrorCode
    objLog.WriteLine "Manufacturer: " & objItem.Manufacturer
    objLog.WriteLine "MaxBlockSize: " & objItem.MaxBlockSize
    objLog.WriteLine "MaximumComponentLength: " & objItem.MaximumComponentLength
    objLog.WriteLine "MaxMediaSize: " & objItem.MaxMediaSize
    objLog.WriteLine "MediaLoaded: " & objItem.MediaLoaded
    objLog.WriteLine "MediaType: " & objItem.MediaType
    objLog.WriteLine "MinBlockSize: " & objItem.MinBlockSize
    objLog.WriteLine "Name: " & objItem.Name
    objLog.WriteLine "NeedsCleaning: " & objItem.NeedsCleaning
    objLog.WriteLine "NumberOfMediaSupported: " & objItem.NumberOfMediaSupported
    objLog.WriteLine "PNPDeviceID: " & objItem.PNPDeviceID
    objLog.WriteLine "PowerManagementCapabilities: " & objItem.PowerManagementCapabilities
    objLog.WriteLine "PowerManagementSupported: " & objItem.PowerManagementSupported
    objLog.WriteLine "RevisionLevel: " & objItem.RevisionLevel
    objLog.WriteLine "SCSIBus: " & objItem.SCSIBus
    objLog.WriteLine "SCSILogicalUnit: " & objItem.SCSILogicalUnit
    objLog.WriteLine "SCSIPort: " & objItem.SCSIPort
    objLog.WriteLine "SCSITargetId: " & objItem.SCSITargetId
    objLog.WriteLine "Size: " & objItem.Size
    objLog.WriteLine "Status: " & objItem.Status
    objLog.WriteLine "StatusInfo: " & objItem.StatusInfo
    objLog.WriteLine "SystemCreationClassName: " & objItem.SystemCreationClassName
    objLog.WriteLine "SystemName: " & objItem.SystemName
    objLog.WriteLine "TransferRate: " & objItem.TransferRate
    objLog.WriteLine "VolumeName: " & objItem.VolumeName
    objLog.WriteLine "VolumeSerialNumber: " & objItem.VolumeSerialNumber
    objLog.WriteLine
	objLog.WriteLine
Next
 
MsgBox "Done"

Open in new window

Author

Commented:
I get nothing in the txt file created... I have the cd drives disabled. will this be an issue?
This is dirty and seems to not get the next CD even if there is one that is enabled. I ahve 2 on this test system and disabled one and once WMI sees one is disabled, it didn't even process the next one.
'Get Computer Hardware and store into a local file
 
On Error Resume Next
 
Dim objFSO, objLog, strLogFile, strLogPath, strComputerName, strDate, strHardware, strtmp, iCount, bHadDrive  
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
 
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
'strLogPath = "\\Servername\Serverfolder\"
strLogPath = "C:\"
 
strDate = Right("0" & Day(Date), 2) & "-" & Right("0" & Month(Date),2) & "-" & Year(Date)
 
 
icount = 1
 
Do Until iCount = 255
	strLogFile = strLogPath & strComputerName & "_" & strDate & "-" & icount & ".txt"
	If objFSO.FileExists( strLogFile ) Then 
		iCount = iCount + 1
	Else
		exit Do
	End If
Loop
 
' If we have more than 255 maybe do some cleanup or something and start over with logfiles
' Call LogFileCleanup
' strLogFile = strLogPath & strComputerName & "_" & strDate & "-1" & ".txt"
 
Set objLog = objFSO.OpenTextFile( strLogFile, 2, True)
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_Processor")
	strHardware = procItem.Name & "\"
Next
 
For Each procItem In GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
	strHardware = strHardware & Round(procItem.TotalPhysicalMemory / 1048576, 0) & " MB\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_DiskDrive")
	strHardware = strHardware & Round(procItem.Size / 1073741824, 0) & "GB\"
Next
 
bHadDrive = False
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_FloppyDrive")
	strHardware = strHardware & procItem.Caption & "\"
	bHadDrive = True
Next
 
If bHadDrive = False Then
	strHardware = strHardware & "NO FLOPPY\"
End If
 
bHadDrive = False
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_CDRomDrive")
	strHardware = strHardware & procItem.Caption & "\"
	bHadDrive = True
Next
 
If IsNull(procItem.Caption) = True Then
	strHardware = strHardware & "CD/DVD DISABLED\"
End If
	
 
If bHadDrive = False Then
	strHardware = strHardware & "NO CD/DVD DRIVES\"
End If
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
	If procItem.IPEnabled = True Then
		strHardware = strHardware & procItem.MACAddress & "\"
	End If	
Next
 
iCount = 0
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	iCount = iCount + 1
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemoryArray")
	strHardware = strHardware & procItem.MemoryDevices & "\" & procItem.MemoryDevices - iCount & "\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	strHardware = strHardware & Round(procItem.Capacity / 1048576, 0) & " MB\"
Next
 
objLog.WriteLine strHardware
 
'Remove this line if you don't want confirmation that its done
MsgBox "All Done"

Open in new window

Author

Commented:
Thanks
When the DVD is disabled i get as this

Intel(R) Pentium(R) III Xeon processor\4095 MB\546GB\NO FLOPPY\CD/DVD DISABLED
And when enabled i get this
Intel(R) Pentium(R) III Xeon processor\4095 MB\546GB\NO FLOPPY\HL-DT-ST RW/DVD GCC-T10N\CD/DVD DISABLED
try this
'Get Computer Hardware and store into a local file
 
On Error Resume Next
 
Dim objFSO, objLog, strLogFile, strLogPath, strComputerName, strDate, strHardware, strtmp, iCount, bHadDrive  
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
 
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
'strLogPath = "\\Servername\Serverfolder\"
strLogPath = "C:\"
 
strDate = Right("0" & Day(Date), 2) & "-" & Right("0" & Month(Date),2) & "-" & Year(Date)
 
 
icount = 1
 
Do Until iCount = 255
	strLogFile = strLogPath & strComputerName & "_" & strDate & "-" & icount & ".txt"
	If objFSO.FileExists( strLogFile ) Then 
		iCount = iCount + 1
	Else
		exit Do
	End If
Loop
 
' If we have more than 255 maybe do some cleanup or something and start over with logfiles
' Call LogFileCleanup
' strLogFile = strLogPath & strComputerName & "_" & strDate & "-1" & ".txt"
 
Set objLog = objFSO.OpenTextFile( strLogFile, 2, True)
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_Processor")
	strHardware = procItem.Name & "\"
Next
 
For Each procItem In GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
	strHardware = strHardware & Round(procItem.TotalPhysicalMemory / 1048576, 0) & " MB\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_DiskDrive")
	strHardware = strHardware & Round(procItem.Size / 1073741824, 0) & "GB\"
Next
 
bHadDrive = False
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_FloppyDrive")
	strHardware = strHardware & procItem.Caption & "\"
	bHadDrive = True
Next
 
If bHadDrive = False Then
	strHardware = strHardware & "NO FLOPPY\"
End If
 
bHadDrive = False
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_CDRomDrive")
	strHardware = strHardware & procItem.Caption & "\"
	bHadDrive = True
	strtmp = procItem.Caption
Next
 
If IsEmpty(strtmp) = True Then
	strHardware = strHardware & "CD/DVD DISABLED\"
End If
	
 
If bHadDrive = False Then
	strHardware = strHardware & "NO CD/DVD DRIVES\"
End If
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
	If procItem.IPEnabled = True Then
		strHardware = strHardware & procItem.MACAddress & "\"
	End If	
Next
 
iCount = 0
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	iCount = iCount + 1
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemoryArray")
	strHardware = strHardware & procItem.MemoryDevices & "\" & procItem.MemoryDevices - iCount & "\"
Next
 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	strHardware = strHardware & Round(procItem.Capacity / 1048576, 0) & " MB\"
Next
 
objLog.WriteLine strHardware
 
'Remove this line if you don't want confirmation that its done
MsgBox "All Done"

Open in new window

Author

Commented:
Thank you works perfect
Can i know your name? If you dont mind....
Aaron and I'm very glad to help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial