NTTIT
asked on
Log on script (2)
With thanks to AndrewJDavis, the script when I log into windows takes down the username perfectly. But as I am on a server, it would be good if the computer name could also be taken down. Can someone add to this script so that the computer name is taken down too
DIM fso, NTBMFile, NTBMNet, strUser
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set NTBMNet = WScript.CreateObject("WScr ipt.Networ k")
strUser =NTBMNet.UserName
on error resume next
'WScript.Echo "Starting Script!"
' You will need to change this line to reflect the file that you want to store the info in.
Set NTBMFile = fso.OpenTextFile("H:\saved .txt", 8, True)
NTBMFile.Write((Date) & " , ")
NTBMFile.Write((Time) & " , ")
NTBMFile.Writeline (struser &" , Logged ON")
NTBMFile.Close
'In the final version comment out or delete the line below so that it doesnt popup for your end user it is only for testing purposes.
WScript.Echo "Finished"
Thanks Guys
DIM fso, NTBMFile, NTBMNet, strUser
Set fso = CreateObject("Scripting.Fi
Set NTBMNet = WScript.CreateObject("WScr
strUser =NTBMNet.UserName
on error resume next
'WScript.Echo "Starting Script!"
' You will need to change this line to reflect the file that you want to store the info in.
Set NTBMFile = fso.OpenTextFile("H:\saved
NTBMFile.Write((Date) & " , ")
NTBMFile.Write((Time) & " , ")
NTBMFile.Writeline (struser &" , Logged ON")
NTBMFile.Close
'In the final version comment out or delete the line below so that it doesnt popup for your end user it is only for testing purposes.
WScript.Echo "Finished"
Thanks Guys
...oops - and modify this line:
NTBMFile.Writeline (struser & " Logged on to " & strPC)
NTBMFile.Writeline (struser & " Logged on to " & strPC)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It didn't add anything to the .txt file
For clarity, also add this constant:
Const ForAppend=8
DIM fso: Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim NTBMNet: Set NTBMNet = WScript.CreateObject("WScr ipt.Networ k")
strUser =NTBMNet.UserName
strPC=NTBMNet.ComputerName
Dim NTBMFile: Set NTBMFile = fso.OpenTextFile("H:\saved .txt", ForAppend, True)
NTBMFile.WriteLine(Date & " , " & Time & vbNewLine & strUser & ", Logged On," & strPC)
NTBMFile.Close
WScript.Echo "Finished"
Const ForAppend=8
DIM fso: Set fso = CreateObject("Scripting.Fi
Dim NTBMNet: Set NTBMNet = WScript.CreateObject("WScr
strUser =NTBMNet.UserName
strPC=NTBMNet.ComputerName
Dim NTBMFile: Set NTBMFile = fso.OpenTextFile("H:\saved
NTBMFile.WriteLine(Date & " , " & Time & vbNewLine & strUser & ", Logged On," & strPC)
NTBMFile.Close
WScript.Echo "Finished"
Didn't or did? Looks like the Q is closed? : \
ASKER
Your help was great Sirbounty, thank you so much
Set fso = CreateObject("Scripting.Fi
Set NTBMNet = WScript.CreateObject("WScr
strUser =NTBMNet.UserName
'simply add this next line...
strPC=NTBMNet.Computername
on error resume next