Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create log file during logon script 2

Status
Not open for further replies.

puppet

IS-IT--Management
Dec 13, 2001
140
Hi,

I have very limited scripting knowledge and have a requirement to come up with the following in such a short time that I will not be able to learn how to do this on my own yet.

I am planning on using the brilliant logon script from:


What I would like to do in the add-on section would be to create a text file on each users J: drive (their home drives that will still be mapped through the profile tab for the time being) that logs the username, the computername and the current time. I would like to append to this file each time they logon for a month and then create a new file. I would like to keep the old log file for a month and then have the log file that is two months old deleted.

Hope this makes sense! Ideally I would like to have all users write to the one log file on a central server but imagine there would be problems with write access if two people are logging on at once...

Any ideas much appreciated!

Thanks
 
I wanted to do this too. I came across the same FAQ and have made it work for me. I just started the switch from .cmd logonscripts to .VBS. I always had my users, computername, time, etc written to c:\logon.log using my .cmd. I did some research and didn't want to add many lines of code and figure out how to pass the com specs. I just did this to complete the job, and someday I will figure it out and do it right.

WSHShell.Run "cmd /c echo %username% - %time% - %date% - %computername% - Supervisors >> c:\login.log"

My login script is a little diffrent. I use passed variables to map the default printer, since people move around alot here (All other printers in the building are mapped as well). All else is controlled by the group membership, like the FAQ.

Select Case Wscript.Arguments.Item(0)
Case "4050_first_floor"
' ======= Mapping 4050_first_floor As Default with Others as Spares ======

WSHNetwork.AddWindowsPrinterConnection "\\server\printer"
WshNetwork.SetDefaultPrinter "\\server\printer"
WSHNetwork.AddWindowsPrinterConnection "\\server\printer2"

so my script starts like this :
logonscript.vbs 4050_first_floor

One other change is how I unmap / map drives. I didn't want to unmap everything, just the drives I was replacing.

WSHNetwork.RemoveNetworkDrive "y:", True, True
WSHNetwork.RemoveNetworkDrive "z:", True, True
script.sleep 300
WSHNetwork.MapNetworkDrive "y:", "\\server\files"
WSHNetwork.MapNetworkDrive "z:", "\\server\files2"
 
freezeACC, Why not using the ComputerName, UserDomain and UserName properties of the WshNetwork object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks FreezeACC - that is great. Anyone got any ideas about writing to a single central log file?

Oops PHV - gave you your star by mistake! Enjoy.

Cheers
 
The only way to do central logging is via a database. You can do it with flat files, but it would be a space hogging nightmare.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
PHV,
Like I said, I am a VBS login script newbie too. I was able to do this with one line of code, and since I write out to c:\logon.log 7 times (each group gets a different login.log messages) in my script that was the easiest. I was in a hurry too.

Now that I think about it I can probably just do it with a for statement. I just need to bone up on my file writing. Any samples PHV?

Psudo code:
After the end of all group membership case statements...

write to file c:\logon.log %username% - %time% - %date% - %computername% -

For Each GroupObj In UserObj.Groups
write user's group to file c:\logon.log

close file
 
Just add name or whatever to the line
[tt]>WSHShell.Run "cmd /c echo %username% - %time% - %date% - %computername% - Supervisors >> c:\login.log"[/tt]
like this.
[tt]WSHShell.Run "cmd /c echo %username% - %time% - %date% - %computername% - [blue]" & GroupObj.name & "[/blue] - Supervisors >> c:\login.log"
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top