-2

我有这个脚本,它正在创建和更新一个名为 Machine.txt 的文本文件,并用具有这种格式的行列表(脚本运行时的用户名、时间和日期)填充它。

我在登录时运行它。

我想要做的是为每个登录的用户创建一个新的文本文件。

例如,如果用户名为 fred,我希望脚本创建 fred.txt。

有任何想法吗?

使用的脚本如下所示,我已将文件位置和名称替换为“文件路径和名称”,希望您能提供任何帮助。

Set WSHShell = WScript.CreateObject ("WScript.Shell")
Set WSHNetwork = WScript.CreateObject ("WScript.Network")
Set WSHSysEnv = WSHShell.Environment ("PROCESS")

On Error Resume Next 

' Check what OS is being used

Dim valOS

    valOS = WSHShell.RegRead ("HKLM\SOFTWARE\Microsoft\Windows     NT\CurrentVersion\ProductName")


Dim valPath, valLocation

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
valMachine = objEnv("COMPUTERNAME")
valDate = date
valTime = time

' This section of the script look for a hidden file on a users private share. This   file is used to store a list of 
' machines that a client has logged onto and the date and time that they logged on


Set oFSO = CreateObject ("Scripting.FileSystemObject")

If oFSO.FileExists ("filepath and name") Then ' If this file exists open the file for  appending

    Set oAppend = oFSO.OpenTextFile ("filepath and name",8) ' Open the text file for  appending
    oAppend.Writeline valMachine & "," & valDate & "," & valTime ' Write the machine name, date and time the the user logged onto the client
    oAppend.close ' Close the text file connection
    valPath = ""
    valDate = ""
    valTime = ""
Else
    Set oStream = oFSO.CreateTextFile ("filepath and name") ' Create the file
    Set objFile = oFSO.GetFile ("filepath and name") ' Attach to the file
    objFile.Attributes = 2 ' Change the file attribute to hidden
    oStream.Writeline valMachine & "," & valDate & "," & valTime ' Write the machine      name, date and time the the user logged onto the client
    oStream.close ' Close the text file connection
    valPath = "" ' Clear the valPath variable
valDate = "" ' Clear the valDate variable
valTime = "" ' Clear the valTime variable

End If 

wscript.quit
4

1 回答 1

0

尝试这个:

Dim objNetwork
Dim userName

Set objNetwork = CreateObject("WScript.Network")
userName = objNetwork.UserName

将 userName 分配为您的文件名,扩展名为 .txt

于 2012-11-30T17:12:48.610 回答