I am currently writing a script which parses the ServiceTage, Computername and Username from a computer and outputs it to a text file on a share, but it seems that it always overwrites the data there rather than adding to it.
The code is as follows:
'Get Dell Service Tag Info
set ProSet = GetObject("winmgmts:").InstancesOf("Win32_BIOS")
Set ProSet1 = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
For each Pro in ProSet
For each Pro1 in ProSet1
ServiceTag=Pro.SerialNumber
exit for
Next
exit for
Next
'get username and computername, could also be asked in a batch
Set oShell = WScript.CreateObject("WScript.Shell")
Set oShellEnv = oShell.Environment("Process")
sComputerName = oShellEnv("ComputerName")
sUsername = oShellEnv("username")
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("\\xx.xx.xx.xx\Support\DataLog.txt", 8, True)
path = filesys.GetAbsolutePathName("\\xx.xx.xx.xx\Support\DataLog.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine sUsername & ", " & sComputerName & ", " & ServiceTag
filetxt.Close
Thank you!
Best Answer
Straight from the VBScript Docs:
From your code:
Diagnosis:
You call .CreateTextFile() with the parameters of .OpenTextFile()
Remedy:
Use .OpenTextFile():