VBScript日志记录 [英] VBScript Logging
问题描述
您好,
我有一个登录时使用的日志,用于捕获某些信息(时间/日期,计算机名称,用户名,IP和Mac地址等)到目前为止我一直很好。但是,我有时需要将这些例程用于我分配给我的
的其他任务。我需要能够(当然)记录每个登录事件,但是,我希望它搜索以前的条目(通过计算机名称),而不是创建一个新的条目,用新的登录信息修改以前的条目,我不知道
如何实现这一点。你能不能为我提供了一种基于计算机名更新现有条目的方法吗?
I have a log that I use during logon that captures certain information (time/date, computer name, user name, ip and mac address etc. and has been working well for me to date. However, I have had need on occasion to use these routines for other tasks I was assigned to do. I need to be able to (of course) log each login event, however, I would like it to search for a previous entry (via computer name) and instead of creating a new entry, to modify the previous entry with new logon information, and I am not sure how to accomplish this. Can you provide me with a way to update an existing entry based upon the computer name?
以下是我目前正在使用的一些代码,它非常基本但可以完成工作。
Here is some of the code I'm using at the moment, its pretty basic but gets the job done.
Sub LogIt ()
路径 = " \\Server\share \ Logon Info.csv"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
如果 fso.FileExists (路径 )= 0 然后
'未找到日志文件 - 创建日志文件
设置 oFile = fso.CreateTextFile (路径 , True )
oFile.WriteLine <跨度>(跨度> <跨度>"日期&安培;时间" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; 跨度> <跨度>"计算机名" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; 跨度> <跨度>" NT用户ID" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; 跨度> <跨度>"名字" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; 跨度> <跨度>"姓" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; 跨度> <跨度>"操作系统" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; 跨度> <跨度>"版本" 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; " IP
地址" & 跨度> <跨度>"," 跨度> <跨度>&安培; " Mac地址" & vbCrLf )
oFile.Close
WScript.Sleep ( 500 )
结束 如果
设置 oFile = fso.OpenTextFile (路径 ,ForAppending )
oFile.Write 跨度> <跨度>(跨度> <跨度>现在跨度> <跨度>()及跨度> <跨度>"," 跨度> <跨度>&安培; strComputer的< /跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; strUserName中跨度> <跨度>&安培; 跨度> <跨度>"," ; 跨度> <跨度>&安培; strGivenName 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; oUser.sn 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; strCaption 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培; STRAR CH 跨度> <跨度>&安培; 跨度> <跨度>"," 跨度> <跨度>&安培;条跨度> <跨度>&安培; 跨度> <跨度>" ," 跨度> <跨度>&安培; strMac 跨度> <跨度>&安培; vbCrLf )
oFile.Close
结束 Sub
任何帮助都将不胜感激。
Sub LogIt()
Path = "\\Server\share\Logon Info.csv"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
If fso.FileExists(Path)= 0 Then
'Log File not found - Create Log File
Set oFile = fso.CreateTextFile(Path, True)
oFile.WriteLine("Date & Time" & "," & "Computer Name" & "," & "NT User ID" & "," & "First Name" & "," & "Last Name" & "," & "Operating System" & "," & "Version" & "," & "IP
Address" & "," & "Mac Address" & vbCrLf)
oFile.Close
WScript.Sleep(500)
End If
Set oFile = fso.OpenTextFile(Path, ForAppending)
oFile.Write(Now() & "," & strComputer & "," & strUserName & "," & strGivenName & "," & oUser.sn & "," & strCaption & "," & strArch & "," & strIP & "," & strMac & vbCrLf)
oFile.Close
End Sub
Any help would be appreciated.
推荐答案
您要求有人为您设计解决方案。 我们可以回答具体问题。
You are asking for someone to design a solution for you. We can answer specific question.
操作和编辑您需要具有结构和访问方法的文件。 可以选择性地编辑INI文件或XML文件。 每次编辑都必须重新创建一个文本文件,这使得它成为一个非常糟糕的选择。
TO manipulate and edit files you need to have a structure and a method of access. An INI file or XML file can be selectlvely edited. A text file has to be recreated on each edit making it a very poor choice.
为什么你认为你需要这样做?
Why do you think you need to do this?
这篇关于VBScript日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!