下面是我的 VBS 代码。我承认,我对此非常陌生,因为我把它作为工作中的工作。我需要创建一个登录/注销脚本,它将捕获某些信息并将其存储在 csv 文件中。我能够获取信息并将其存储在 csv 文件中,但是当我尝试再次执行此操作时,我希望它创建另一行并将更新的信息存储在那里。我不断得到这些亚洲字符。似乎是什么问题。
这是我第二次单击注销脚本时得到的内容:沩牵琠硥⁴潧獥栠牥
' ******************** Log Off Script **********************************
'Script to write Logoff Data Username, Computername to eventlog.
Dim objShell, WshNetwork, PCName, UserName, strMessage, strContents, logDate, logTime
Dim strQuery, objWMIService, colItems, strIP, rowCount
' Constants for type of event log entry
const EVENTLOG_AUDIT_SUCCESS = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
logDate = Date()
logTime = Time()
PCName = WshNetwork.ComputerName
UserName = WshNetwork.UserName
strMessage = "Logoff Event Data" & "PC Name: " & PCName & "Username: " & UserName & "Date: " & logDate & "Time: " & logTime
If (objFSO.FileExists("test.csv")) Then
WScript.Echo("File exists!")
dim filesys, filetxt
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("test.csv", ForAppending, True)
filetxt.WriteLine(vbNewline & "Your text goes here.")
filetxt.Close
Else
rowCount = rowCount + 1
WScript.Echo("File does not exist! File Created!")
Set csvFile = objFSO.CreateTextFile("test.csv", _
ForWriting, True)
objShell.LogEvent EVENTLOG_AUDIT_SUCCESS, strMessage
csvFile.Write strMessage
csvFile.Writeline
End If
WScript.Quit