Jump to content

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


Recommended Posts

Posted

this is what i do in the login script

 

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

Posted

This should do the trick!

 

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

 

 '  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 

Posted

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

 

'  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 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...