我想创建一个vbs脚本,该脚本将在用户登录时输出带有用户名的文本文件。例如,当john登录时,它将创建john.txt到选定的文件夹。
答案 0 :(得分:1)
Dim oFSO, oTxtFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("C:\Logs\" & CurrentUser() & ".txt") Then
Msgbox "File Exist"
Set oTxtFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Logs\" & CurrentUser() & ".txt",8)
Else
Set oTxtFile = oFSO.CreateTextFile("C:\Logs\" & CurrentUser() & ".txt")
Msgbox "File Created"
End If
oTxtFile.WriteLine(CurrentUser() & " logged in at " & now() & Chr(13) & Chr(10))
Function CurrentUser()
Set objNetwork = CreateObject("Wscript.Network")
CurrentUser = objNetwork.username
End Function