troubleshooting Question

do not allow duplicates on vbs output

Avatar of EfrenM
EfrenMFlag for United States of America asked on
Visual Basic ClassicVB Script
4 Comments1 Solution372 ViewsLast Modified:
Below is a script to audit the computer when a user logs on, it makes the output fine, but it allows duplicates, does anyone know how to make it so it doesnt allow duplicates based on computer name and serial number?
Option Explicit	
 
	Call VendorInfo
 
 Sub VendorInfo
 
	Dim fso, objWMIService, objItem, oFile 
	Dim sFileLocation, strHeader, strComputer
	Dim strOutput, strResults
	Dim colItems
	
	Const wbemFlagReturnImmediately = &h10
	Const wbemFlagForwardOnly = &h20
	Const ForReading = 1
	Const ForWriting = 2
	Const ForAppending = 8
 
' Initialize the variables	
	sFileLocation = "c:\KKVendor.xls"	' Put your filename and network share here i.e. \\server\share\filename.csv
	strHeader = "UserName,ComputerName,Domain,IP Address,ID No.,Name,Vendor,Version,Date" & vbNewLine 
	strComputer = "."
 
' Create the objects
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
	
' Get Username & Computer & Domain
	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
		wbemFlagReturnImmediately + wbemFlagForwardOnly)
		
		For Each objItem In colItems
			strOutput = strOutput & objItem.UserName & ","
			strOutput = strOutput & objItem.Name & ","
			strOutput = strOutput & objItem.Domain & "," 
		Next
 
 
'Get IP Address	
	Set colItems = objWMIService.ExecQuery _
		("Select IPAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
		
		For Each objItem In colItems
			If objItem.IPaddress(0) <> "0.0.0.0" Then
				strOutput = strOutput & objItem.IPAddress(0) & ","
				Exit For	' We only want the first one it comes across
			End If
		Next
 
' Get ID No. Name, Vendor and Version
	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _
		wbemFlagReturnImmediately + wbemFlagForwardOnly)
		
		For Each objItem In colItems
			strOutput = strOutput & objItem.IdentifyingNumber & ","
			strOutput = strOutput & objItem.Name & ","
			strOutput = strOutput & objItem.Vendor & ","
			strOutput = strOutput & objItem.Version & "," 
                        strOutput = strOutput & Date() & vbnewline
 
 
		Next
 
' Write Results To File
	If fso.FileExists(sFileLocation) = False Then
		' Create and write to file with header
		Set oFile = fso.OpenTextFile(sFileLocation, ForWriting, True)
	
			If Err.Number <> 0 Then
				' You could write to the event log here
				Exit Sub
			End If
		
		strResults = oFile.Write(strHeader & strOutput)
	Else
		' File exists so append to it without header
		Set oFile = fso.OpenTextFile(sFileLocation, ForAppending, False)
 
			If Err.Number <> 0 Then
				' You could write to the event log here
				Exit Sub 
			End If
 
		strResults = oFile.Write(strOutput)
	End If 
 
 End Sub
ASKER CERTIFIED SOLUTION
Krys_K

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros