Solved

Log on script (2)

Posted on 2007-03-26
7
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

630 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