Solved

Log on script (2)

Posted on 2007-03-26
7
173 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article discusses four methods for overlaying images in a container on a web page
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

825 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