Link to home
Start Free TrialLog in
Avatar of jsparnova
jsparnova

asked on

VB scripting question regarding variables

I have a vb script to extract the info from the event log and write it to a txt file on a network share. The problem that I have is that I want to be able to run this on all of my users machines and have it write to a txt file that includes the username or hostname variable so i can have a seperate file from each machine. (hostname.txt otherhostname.txt...). I am a scripting newbie, so any help would be great.

thanks
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where LogFile='Application'")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\\mar\EVT_LOGS\%USERNAME%")
 
For Each objEvent in colEvents
    strTimeWritten = objEvent.TimeWritten
 
    dtmTimeWritten = CDate(Mid(strTimeWritten, 5, 2) & "/" & _
        Mid(strTimeWritten, 7, 2) & "/" & Left(strTimeWritten, 4) _
            & " " & Mid (strTimeWritten, 9, 2) & ":" & _
                Mid(strTimeWritten, 11, 2) & ":" & Mid(strTimeWritten, 13, 2))
 
    dtmDate = FormatDateTime(dtmTimeWritten, vbShortDate)
    dtmTime = FormatDateTime(dtmTimeWritten, vbLongTime)
 
    strEvent = dtmDate & vbTab
    strEvent = strEvent & dtmTime & vbTab
    strEvent = strEvent & objEvent.SourceName & vbTab
    strEvent = strEvent & objEvent.Type & vbTab
    strEvent = strEvent & objEvent.Category & vbTab
    strEvent = strEvent & objEvent.EventCode & vbTab
    strEvent = strEvent & objEvent.User & vbTab
    strEvent = strEvent & objEvent.ComputerName & vbTab
 
    strDescription = objEvent.Message
    If IsNull(strDescription) Then
        strDescription = "The event description cannot be found."
    End If
    strDescription = Replace(strDescription, vbCrLf, " ")
    strEvent = strEvent & strDescription
 
    objFile.WriteLine strEvent
Next
 
objFile.Close

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TakedaT
TakedaT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jsparnova
jsparnova

ASKER

Thank you so much. this worked perfectly.