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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way to track access to server 1

Status
Not open for further replies.

OLDMO

MIS
Aug 13, 2003
95
US
Does anyone know of something or someway to track who logs on to a server and for what reason. I have a script that takes down the username and time/date to a text file but is the also a way to prompt for a reason for access and write that as well?

-Ryan
 

reason = InputBox("Why are you accessing the server?","What are you trying to do Dave?")

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
What would i need put do to write the answer to a file etc..?

Thx!!
 
I tried this and it's not prompting me.... i should have mentioned that the login scripts i use are .bat files.
 
Sorry I thought you already had it writting to a file. Here is the complete script to do all that you were asking. You need to switch this to a .VBS extension instead of a BAT.


reason = InputBox("Why are you accessing the server?","What are you trying to do Dave?")

Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHNetwork = CreateObject("Wscript.Network")
report = WSHNetwork.Username & " accessed the server at "& Now & " for the following reason:" & vbCrLf
report = report & reason
Set ts = fso.CreateTextFile ("c:\reason.txt", ForAppending)
ts.write report

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
markdmac:

It works great except that after it has run once and the file is written the next time it gives me an error unless I remove the reason.txt file.

It like it's not appending.

any suggestions?
 
Sorry about that. Forgot to define ForAppending. I added some error checking. This will fix it:

CONST ForAppending = 8
reason = InputBox("Why are you accessing the server?","What are you trying to do Dave?")

Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHNetwork = CreateObject("Wscript.Network")
report = WSHNetwork.Username & " accessed the server at "& Now & " for the following reason:" & vbCrLf
report = report & reason & vbCrLf

If Not fso.FileExists("c:\reason.txt") Then
fso.CreateTextFile ("c:\reason.txt")
End If
Set ts = fso_OpenTextFile ("c:\reason.txt", ForAppending)
ts.write report

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
worked like a charm!!!! Thx a bunch!

Just for curiousity.

If I wanted to map a drive and then write the file to a server drive how would I do that.

Will i just change the C:\txtfile.txt to \\servername\share\txtfile.text

That's how I do it with .bat files but I'm not used to working with vbscript.

Thx,
Ryan
 
You can use this to map the drive, then use the drive letter for use withthe file name:

WSHNetwork.MapNetworkDrive "X:", "\\server\Share",True

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I added your line and it's giving me an error say object required WSHNETWORk

Here is the script:

ONST ForAppending = 8
reason = InputBox("Why are you accessing the server? Please give a reason. note: A blank response will be questioned by OMNB management!","Authorized Personnel Only!!!!")

WSHNetwork.MapNetworkDrive "w:", "\\*******\********",True
Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHNetwork = CreateObject("Wscript.Network")
report = WSHNetwork.Username & " accessed the server at "& Now & " for the following reason:" & vbCrLf
report = report & reason & vbCrLf

If Not fso.FileExists("w:\sunshineserverlogin.txt") Then
fso.CreateTextFile ("w:\serverlogin.txt")
End If
Set ts = fso_OpenTextFile ("w:\sunshineserverlogin.txt", ForAppending)
ts.write report
 
I've got it where it already seeing the mapped drive. How do I get this dissconnect drive W before it starts?
 
Hi OLDMO.

Move the following line somewhere above the map command line:

Set WSHNetwork = CreateObject("Wscript.Network")

That will get rid of the error for object required.

To delete a mapped drive you would use this:

WSHNetwork.RemoveNetworkDrive "W:"


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top