Solved

Log on script (2)

Posted on 2007-03-26
7
170 Views
Last Modified: 2007-03-26
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.FileSystemObject")
Set NTBMNet = WScript.CreateObject("WScript.Network")
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
0
Comment
Question by:NTTIT
  • 5
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
DIM fso, NTBMFile, NTBMNet, strUser
Set fso = CreateObject("Scripting.FileSystemObject")
Set NTBMNet = WScript.CreateObject("WScript.Network")
strUser =NTBMNet.UserName
'simply add this next line...
strPC=NTBMNet.Computername
on error resume next
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
...oops - and modify this line:

NTBMFile.Writeline (struser & " Logged on to " & strPC)
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
Here's a condensed version (scratch my last comment, as I see you want a CSV)

DIM fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim NTBMNet: Set NTBMNet = WScript.CreateObject("WScript.Network")
strUser =NTBMNet.UserName
strPC=NTBMNet.ComputerName
Dim NTBMFile: Set NTBMFile = fso.OpenTextFile("H:\saved.txt", 8, True)
NTBMFile.WriteLine(Date & " , " & Time & vbNewLine & strUser & ", Logged On," & strPC)
NTBMFile.Close
WScript.Echo "Finished"
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:NTTIT
Comment Utility
It didn't add anything to the .txt file
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
For clarity, also add this constant:

Const ForAppend=8
DIM fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim NTBMNet: Set NTBMNet = WScript.CreateObject("WScript.Network")
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"
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Didn't or did?  Looks like the Q is closed? : \
0
 

Author Comment

by:NTTIT
Comment Utility
Your help was great Sirbounty, thank you so much
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now