-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 に答える