Solved

Log on script (2)

Posted on 2007-03-26
7
172 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
ID: 18797250
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
ID: 18797257
...oops - and modify this line:

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

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18797260
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

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

Expert Comment

by:sirbounty
ID: 18797281
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
ID: 18797286
Didn't or did?  Looks like the Q is closed? : \
0
 

Author Comment

by:NTTIT
ID: 18797697
Your help was great Sirbounty, thank you so much
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

15 Experts available now in Live!

Get 1:1 Help Now