Solved

Script to write user name and computer name to file

Posted on 2009-04-07
4
439 Views
Last Modified: 2012-06-27
Hi All,

Can a scripting person assist by creating a Vb script that will

1. Create a file to a network share using \\server\share
2. Create the text file with the user name and Date as the file name
3. Save the User Name, Computer Name, Logon Time and Date on separate lines

User Name: Marvin
Computer Name: Themartian
Logon Time: 14:32
Date:  08/04/2009

Hope i am not asking to much.

Thanks

Aalborg

0
Comment
Question by:AI-SYD
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
yehudaha earned 500 total points
ID: 24094250
change this line the line of the share you want to save the file

strPath = "\\server\share"
strPath = "\\server\share"
Set objnet = CreateObject("wscript.network")
Set objfso = CreateObject("scripting.filesystemobject")
strDate = Day(Date) & "." & Month(Date) & "." & Year(Date)
Set objlog = objfso.CreateTextFile(strPath & "\" & objnet.UserName & "_" & strDate & ".txt",True)
objlog.WriteLine "User Name: " & objnet.UserName
objlog.WriteLine "Computer Name: " & objnet.ComputerName
objlog.WriteLine "Logon Time: " & Time
objlog.WriteLine "Date: " & Date

Open in new window

0
 
LVL 5

Expert Comment

by:mfhorizon
ID: 24094252
Hi Aalborg,

I think you need to create a cookie using vbscript, that can save different events like name, time etc. You can do it by using following script:

VBScript
=======
Creating a cookie in VBScript uses the document.cookie object:

<SCRIPT LANGUAGE="VBScript">
document.cookie = "User_Name=Marvin; &_
                                path=/; &_
                                expires Sat, 01-Jan-2010 00:00:00 GMT"
document.cookie = "Computer_Name=Themartian; &_
                                path=/; &_
                                expires Sat, 01-Jan-2010 00:00:00 GMT"

document.cookie = "Logon_Date=Date; &_
                                path=/; &_
                                expires Sat, 01-Jan-2010 00:00:00 GMT"
document.cookie = "Logon_Time=Time; &_
                                path=/; &_
                                expires Sat, 01-Jan-2010 00:00:00 GMT"
</SCRIPT>


To retreive these values next time on your website you can use
NameVariable = getCookie("User_Name")
ComputerNameVariable = getCookie("Computer_Name")
TimeVariable = getCookie("Logon_Time")
DateVariable = getCookie("Logon_Date")


0
 

Author Closing Comment

by:AI-SYD
ID: 31567888
Thanks it worked perfectly.
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 24094443
glad to help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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