Hi,
Bit of a noob when it comes to this I'm afraid :-(
I have a script that pics up computer names (that are on the network) from a file (comps.txt) and creates another file with information (results.txt) about the PC's in the list.
What I want to end up with is a file with the computer name, followed by the serial number of the PC and the username of the person who's PC it is. I have found a script that will do most of this but I cannot integrate the code for finding the user name.
The script is as follows:
----------------------------------------------------------------------------------------------------------------
'START CODE
const FSO_READ_MODE = 1
const FSO_WRITE_MODE = 2
const COMPUTER_NAMES_FILE = "D:\comps.txt"
const RESULTS_FILE = "D:\results.txt" 'warning - will be overwritten each time script runs
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
ReadFile(COMPUTER_NAMES_FILE)
Set fso = Nothing
function CheckSerial(ComputerName)
Dim System
Dim retVal
retVal=""
if Wscript.Arguments.Count > 0 then
sSystem=Wscript.Arguments(0)
end if
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
retVal = retVal & "The serial number for " & ComputerName & " is: " & SN.SerialNumber
Next
CheckSerial = retVal
end function
function ReadFile(sFilePath)
If fso.FileExists(sFilePath) then
'The file exists, so open it and output its contents
dim file: set file = fso.OpenTextFile(sFilePath, FSO_READ_MODE)
dim sLine
dim sResults: sResults = ""
Do While file.AtEndOfStream = False
sLine = file.ReadLine
sResults = sResults & CheckSerial(sLine) & vbcrlf
Loop
file.Close()
Set file = Nothing
WriteResults sResults
Else
'The file did not exist
msgbox sFilePath & " was not found."
End If
end function
sub WriteResults(sResults)
dim file: set file = fso.OpenTextFile(RESULTS_FILE, FSO_WRITE_MODE, true)
file.write(sResults)
file.Close()
Set file = Nothing
end sub
'END CODE
----------------------------------------------------------------------------------------------------------------
If anyone could shed any light on how I can get the user name into the text file as well I would be very greatful.
Thanks,
Giles
'Yotam
'START CODE
const FSO_READ_MODE = 1
const FSO_WRITE_MODE = 2
const COMPUTER_NAMES_FILE = "c:\comps.txt"
const RESULTS_FILE = "c:\results.txt" 'warning - will be overwritten each time script runs
Dim fso: Set fso = CreateObject("Scripting.Fi
ReadFile(COMPUTER_NAMES_FI
Set fso = Nothing
function CheckSerial(ComputerName)
Dim System
Dim retVal
retVal=""
if Wscript.Arguments.Count > 0 then
sSystem=Wscript.Arguments(
end if
winmgmt1 = "winmgmts:{impersonationLe
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
retVal = retVal & "The serial number for " & ComputerName & " is: " & SN.SerialNumber
Next
CheckSerial = retVal
end function
function CheckLoggedOn(ComputerName
Dim retVal
retVal=""
if Wscript.Arguments.Count > 0 then
sSystem=Wscript.Arguments(
end if
winmgmt1 = "winmgmts:{impersonationLe
Set objWMIService = GetObject(winmgmt1)
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
retVal = retVal & "Loggedon users of " & ComputerName & " are: "
For Each objComputer in colComputer
retVal = retVal & CRLF & objComputer.UserName
Next
CheckLoggedOn = retVal
end function
function ReadFile(sFilePath)
If fso.FileExists(sFilePath) then
'The file exists, so open it and output its contents
dim file: set file = fso.OpenTextFile(sFilePath
dim sLine
dim sResults: sResults = ""
Do While file.AtEndOfStream = False
sLine = file.ReadLine
sResults = sResults & CheckSerial(sLine) & vbcrlf & CheckLoggedOn(sLine) & vbcrlf
Loop
file.Close()
Set file = Nothing
WriteResults sResults
Else
'The file did not exist
msgbox sFilePath & " was not found."
End If
end function
sub WriteResults(sResults)
dim file: set file = fso.OpenTextFile(RESULTS_F
file.write(sResults)
file.Close()
Set file = Nothing
end sub
'END CODE