Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write Username/Computername to Log File 1

Status
Not open for further replies.

cwsstins

MIS
Aug 10, 2004
412
US
I got the code below from somewhere on this site, to produce a box displaying the network username and computername.

I'd like to modify it to write that data (along with date/time, if feasible) to a log file instead...

Code:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Username: " & WshNetwork.UserName  + Chr(13) + "Computer Name: " & WshNetwork.ComputerName

Any help appreciated...

stinsman
 
Take a look at FileSystemObject

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
OK, I've got the code to create a new text file and write a line of text to it. I need to be able to append to it so that each time a user runs the script, the next line in the log will indicate their information. Right now, each time I run it, it overwrites...

Code:
Dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\test.log", True)

Set WshNetwork = WScript.CreateObject("WScript.Network")

path = filesys.GetAbsolutePathName("C:\test.log")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Username: " & WshNetwork.UserName  + Chr(13) + "Computer Name: " & WshNetwork.ComputerName)
filetxt.Close
 
Set filetxt = filesys.OpenTextFile("c:\test.log", 8)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That works...just out of curiousity, what does the "8" do?
 
Stinsman

the 8 means the file will be appended to...

When you use a filesystemobject you can select
1 = read
2 = write
8 = append

rgds
Al
 
Hello!

I tried this script and it works, how about if you want to include the date and time when the user logon?

Thanks

Solec
 
filetxt.WriteLine("Username: " & WshNetwork.UserName + Chr(13) + "Computer Name: " & WshNetwork.ComputerName) & " Datetime: " & now()
 
Thanks fosterr!!! It worked! Lastly, does someone have a scipt that will logoff the user if its idle for 30 mins? and saved all his work? Thanks

Solec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top