Jump to content

Recommended Posts

Posted

If you track your users logons to a database then you may find this script of some use as well as an exaple of messy coding to give you a chuckle. We have three domains here and this is my solution to quickly VNC into a user to support them without having to track down what PC they are logged into.

 

You will need to make some small ammendments to suit your environment but it should be easy enough to understand.

 

 

Set WshShell 		= 		Wscript.CreateObject("WScript.Shell")
SQLstring		=		"SELECT * FROM [logons]"	
FilterUser		= 		InputBox("Logon name ?", "", "")
	if FilterUser 		<> ""		then SQLstring = SQLstring & " where [user] LIKE '"&FilterUser&"'"
	SQLstring 		= 		SQLstring &  " ORDER BY [id] Desc"
Set oDB 		= 		CreateObject("ADODB.Connection")

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

oDB.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=\\99.99.99.99\logging$\database\logon_watch.mdb"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Set oRS 		= 		oDB.Execute(SQLstring)

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if 	oRS.EOF then
Wscript.echo(vbcrlf &vbcrlf &"Nothing found in the database"&vbcrlf &vbcrlf &"Sorry !!"&vbcrlf &vbcrlf )
Wscript.quit
end if

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

oUSR			=		(oRS.Fields.Item("user").Value)
oPC			=		(oRS.Fields.Item("pc").Value)
oDATE			=		split((oRS.Fields.Item("serverdate").Value),"/")
Set oDB			= 		Nothing
todayDate		=		split(date(),"/")

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if 	(todayDate(0) = oDate(0)) and (todayDate(1) = oDate(1)) or (todayDate(0) = oDate(1)) and (todayDate(1) = oDate(0)) then
WshShell.Run ("z:\!!-exe\vnc.exe " &oPC&":5252")
else
Wscript.echo(oPC & "-not logged on today")
end if 

Posted

What do I have to do with it. This would be useful. Would it work with RM CC3, I think that knows whos logged on where.

 

If we dont track it, how can I do that?

 

Thanks :-)

Posted

Nice post Chris.

 

I'm not sure if it speeds the query up to do "SELECT TOP 1 * FROM [logons]" on line 2. Possibly not significantly.

 

Another tweak would be to check if anyone else has logged on at that PC since FilterUser (meaning FilterUser can't still be logged on). You could just run a 2nd query to find the most recent logon at the PC and then compare names.

 

It might also be nice to have a box pop up to say "user logged on at xx:xx today, connect?". If they logged on at 09:15 and it's lunchtime there's not much point connecting.

 

I'm looking into making our login database track logoff events as well, if only to get an idea of how many PCs are being shut down gracefully. It might also come in handy for scripts like these.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...