+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, Need a vbs scrpit to run that will output to a text file... in Coding and Web Development; for users logged onto a computer in a certain room. Im sure it has been done before but can someone ...
  1. #1
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,772
    Thank Post
    251
    Thanked 220 Times in 168 Posts
    Rep Power
    87

    Need a vbs scrpit to run that will output to a text file...

    for users logged onto a computer in a certain room.

    Im sure it has been done before but can someone point me in the right direction please

    T

  2. #2
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,497
    Thank Post
    101
    Thanked 84 Times in 71 Posts
    Blog Entries
    46
    Rep Power
    37

    Re: Need a vbs scrpit to run that will output to a text file

    this is what i do in the login script

    Code:
    for /f "tokens=1,2,3* delims=/ " %%a in ('date /t') do set date=%%b%%c%%d
    for /f "tokens=1,2 delims=:" %%a in ('time /t') do set time=%%a%%b
    
    echo %date%,%time%,%username% >> \\backup\logs$\computer\%computername%.txt
    echo %date%,%time%,%computername% >> \\backup\logs$\user\%username%.txt

  3. #3

    Join Date
    Sep 2006
    Location
    Essex
    Posts
    777
    Thank Post
    1
    Thanked 31 Times in 29 Posts
    Rep Power
    23

    Re: Need a vbs scrpit to run that will output to a text file

    This should do the trick!

    You can change the location of the userlog.txt file if required.

    Code:
     '  Author:          Darren Mussenden
    '  Purpose:         logs user logons to the specified text file 
    ' ___________________________________________________________________ 
    ' 
    
    
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    Set objNetwork = CreateObject("Wscript.Network") 
    
       Dim fso, f 
       Set fso = CreateObject("Scripting.FileSystemObject") 
    
    'alter the path to the text file as needed for your environment 
    
    Set f = fso.OpenTextFile("C:\userlog.txt", ForAppending, True) 
    
    
    strComputer = objNetwork.ComputerName 
    strUser = objNetwork.UserDomain & Chr(92) & objNetwork.UserName 
    
    
    'alter the text strings as you like 
    f.Write "User " & strUser & " logged on to computer " & strComputer & " at " & Now & vbCrLf & vbcrlf 
    f.Close

  4. #4
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,772
    Thank Post
    251
    Thanked 220 Times in 168 Posts
    Rep Power
    87

    Re: Need a vbs scrpit to run that will output to a text file...

    Thanks for that, will try that later

  5. #5

    Join Date
    Sep 2006
    Location
    Essex
    Posts
    777
    Thank Post
    1
    Thanked 31 Times in 29 Posts
    Rep Power
    23

    Re: Need a vbs scrpit to run that will output to a text file

    You may also like to append logoff events to the text file. The following script will do this.

    Code:
    '  Author:          Darren Mussenden
    '  Purpose:         logs user logoffs to the specified text file 
    
    
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    Set objNetwork = CreateObject("Wscript.Network") 
    
    
       Dim fso, f 
       Set fso = CreateObject("Scripting.FileSystemObject") 
    
    
    'alter the path to the text file as needed for your environment 
       Set f = fso.OpenTextFile("c:\userlog.txt", ForAppending, True) 
    
    
    strComputer = objNetwork.ComputerName 
    strUser = objNetwork.UserDomain & Chr(92) & objNetwork.UserName 
    
    
       'alter the text strings as you like 
       f.Write "User " & strUser & " logged off of computer " & strComputer & " at " & Now & vbCrLf & vbcrlf 
       f.Close

SHARE:
+ Post New Thread

Similar Threads

  1. ICT output specification document
    By Jimbo in forum BSF
    Replies: 26
    Last Post: 30th November 2007, 10:32 AM
  2. Batch: Text file -> Environment variable?
    By PiqueABoo in forum Scripts
    Replies: 5
    Last Post: 13th December 2006, 11:09 PM
  3. Replies: 14
    Last Post: 22nd November 2006, 09:33 AM
  4. URLblacklist.com as text file
    By adamyoung in forum How do you do....it?
    Replies: 11
    Last Post: 9th February 2006, 02:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •