Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Notification script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,32639
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Notification script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Notification script - 3/24/2006 8:04:05 AM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
What I have been tasked to come up with is a script to determine how long a user has been logged into the domain and if its over 24hrs, then display a popup of some type to notify them to log off. I have searched serval things on this site and the internet everything from a countdown script, too reading text files. The SQL script posted here is a good one but way over the top for what they want to do. Here are the dilemas I have faced with each avenue I've thought about. Maybe someone can help with how to resolve each or an alternate solution.

1: A countdown script ran at logon, using wscript.sleep counting down 24hrs. Then displaying a message. Theoreticaly  it could work. But I didn't work with wscript.sleep. Its too weak. The number would be to long. And my fellow scriptors might make fun of me.

2: On our domain we record users login times with LOGTIME.EXE v1.1 Copyright. But the recent logon time is at the end of the text and I don't know how to only read the last line of text. And do a datediff of that.

3: I can't use objUser.LastLogin and then do a datediff becuase lastlogin records the time when a user logs back into a computer. So if they engage screen lock and come back to it, it  returns an in accurate domain logon time.

4:I wanted to use the event logs, but again. Everytime a user logs back onto the computer it records an entry into Security logs, protraying in accurate domain logon time. I thought about creating a new event entry and doing a datediff of the time it was written at login, but I am not sure how to approach that.
 
 
Post #: 1
 
 RE: Notification script - 3/24/2006 8:08:27 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
What if you have the logon script schedule a scheduled task for 24 hours in the future to pop up the message?


Of course you would need to have a logoff script that would remove the scheduled task.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to david.rollins2)
 
 
Post #: 2
 
 RE: Notification script - 3/24/2006 8:14:56 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
im assuming you have a AD domain by saying this, but there is a gpo that you can use to do this i believe.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Notification script - 3/25/2006 7:31:12 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
GPO for this , really?

I would be interested to know where as i would like to use it.

Cheers

(in reply to kirrilian)
 
 
Post #: 4
 
 RE: Notification script - 3/26/2006 11:53:58 PM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
Yes You would be right. I could use Scheduler. I have already looked into this one though. You can't tell it every 24hrs, you also have to specify a time. And I only want the popup for those individuals logged in for more than 24 hrs.

Also, yes I already know about AD. But we don't want to automatically log them off. We just want a notification.

< Message edited by david.rollins2 -- 3/26/2006 11:56:08 PM >

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Notification script - 3/27/2006 12:53:30 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
quote:

ORIGINAL: ebgreen
Of course you would need to have a logoff script that would remove the scheduled task.

I don't think you would need to use a logoff script, just have the logon script look for a previously scheduled task and delete it if present.

quote:

ORIGINAL: david.rollins2

Yes You would be right. I could use Scheduler. I have already looked into this one though. You can't tell it every 24hrs, you also have to specify a time. And I only want the popup for those individuals logged in for more than 24 hrs.


Have the logon script dynamically create it.  I.e. figure out what the time is 24 hours after a logon and create the schedule based on that.

Also, just wondering, but why 24 hours?  Lets say that I log on at 8 am.  When I leave that night, I lock my workstation.  When I come in the next morning and unlock my workstation at 8 am so I can start working, I will get the message to log off.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to david.rollins2)
 
 
Post #: 6
 
 RE: Notification script - 3/27/2006 12:53:44 AM   
  L12

 

Posts: 22
Score: 0
Joined: 1/19/2006
Status: offline
For point 2, you could just use the readline method looping through each line, storing the line data into a variable until you reach the end of the text stream. Once it's finished looping, the variable will contain the data in the last line. Of course you're relying on the last line of text to always contain the date and this may or may not be the case. You may also need to use split to get the actual date if the line contains some other junk.

(in reply to david.rollins2)
 
 
Post #: 7
 
 RE: Notification script - 3/27/2006 1:23:22 AM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
So mbouchard you are saying also run a log off script to delete the task in the event that they, like you said, login at 8am and don't get the message. I understand. Would I use the Now() to set the scheduler?

L12, will the script keep looping or will it just stop at the end of the text? I'm unfamilar with Looping.

(in reply to L12)
 
 
Post #: 8
 
 RE: Notification script - 3/27/2006 1:33:43 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
quote:

ORIGINAL: david.rollins2

So mbouchard you are saying also run a log off script to delete the task in the event that they, like you said, login at 8am and don't get the message. I understand. Would I use the Now() to set the scheduler?

L12, will the script keep looping or will it just stop at the end of the text? I'm unfamilar with Looping.

Actually, Ebgreen suggested it, I was just saying that a logoff script is not really necessary as you can just delete the original scheduled task with the next logon.  I was also wondering why 24 hours and gave an example. 

Also, I think L12 was replying to another post, atleast that is what it seems to me.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to david.rollins2)
 
 
Post #: 9
 
 RE: Notification script - 3/27/2006 6:06:49 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
What about lastLogonTimestamp ???
 
The lastLogon attribute is still present in the Active Directory schema for Windows 2003 and this attribute still isn’t replicated from one domain controller to another. But that’s OK, because there’s a brand-new attribute in the schema: lastLogonTimestamp. This attribute also keeps track of the last time a user logged on to the domain, but – wonder of wonders – this new attribute is replicated from one domain controller to another. Want to know the last time a user logged on? Then just write a script and connect to any domain controller; the value will be the same on each one.

Set objUser = GetObject("LDAP://cn=Ken Myer, ou=Finance, dc=fabrikam, dc=com")
Set objLastLogon = objUser.Get("lastLogonTimestamp")

intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart
intLastLogonTime = intLastLogonTime / (60 * 10000000)
intLastLogonTime = intLastLogonTime / 1440

Wscript.Echo "Last logon time: " & intLastLogonTime + #1/1/1601#

see scripting guy's article.

http://www.microsoft.com/technet/scriptcenter/topics/win2003/lastlogon.mspx

(in reply to david.rollins2)
 
 
Post #: 10
 
 RE: Notification script - 3/27/2006 6:11:24 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I don't know that the real problem is determining the amount of time logged on so much as having the notification occur at a specified time interval. LastLogonTimeStamp will tell you the last time the user loggen on, but how would you determine when to run the script to access it? Every hour? Every 5 minutes? Once a day?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ziminski)
 
 
Post #: 11
 
 RE: Notification script - 3/27/2006 6:27:55 AM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
What I was planning on doing was doing a DateDiff and create a variable from that. If the DateDiff was greater than 27 then display a message.This is the code I was using with LastLogin

;Set objSystemInfo = CreateObject("ADSystemInfo")
;strDNSDomain = objSystemInfo.DomainShortName
;Set wshShell = CreateObject("WScript.Shell")
;strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")
;Set objUser = GetObject("WinNT://" & strDNSDomain & "/" & strUser & ",user")
;Wscript.Echo Now()
;WScript.Echo objUser.LastLogin
;WScript.Echo DateDiff("h", objUser.LastLogin, Now())

I would then take it
;If DateDiff > 27
   Then Do something.

But this code was returning info for the machine. Not the domain.

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Notification script - 3/27/2006 6:37:15 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
ebgreen,
I agree with you're point, now that we know what time you logged in how often do you check? Looks Like David must have some additional specs being that he was planning on using datediff anyway. So if the end objective is to check everybody, why not then run a seperate process to look at all users, if they are logged in and lastlogintime > 24hrs, pop up a window. This could be run at any interval according to the need. In my world (remote)users don't get a choice and are forced off the network after 24 hrs.

Rick

(in reply to ebgreen)
 
 
Post #: 13
 
 RE: Notification script - 3/27/2006 6:46:51 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
So this would be running on a central server? I don't know why but I thought we were looking for a solution that ran on the machine? Or am I simply confused as I often am?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ziminski)
 
 
Post #: 14
 
 RE: Notification script - 3/27/2006 6:52:12 AM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
What I would basically do is develop it as a SMS advertisement. Because we want them to essentially logoff their machines to enable patches that only install when a user logs out. So yes it would be running on a machine.

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: Notification script - 3/29/2006 2:06:05 AM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
How might I return the needed info for the user running the script without changing the user name everytime.
Basically using a wildcard in place of the user name. This is what I tried already but it didn't work.

Set wshShell = CreateObject("WScript.Shell")
Set strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")
Set objUser = GetObject(LDAP://cn=" & strUser ", ou=Finance, dc=fabrikam, dc=com")
Set objLastLogon = objUser.Get("lastLogonTimestamp")

What do I need to do in order to get it to work.

(in reply to ziminski)
 
 
Post #: 16
 
 RE: Notification script - 3/29/2006 2:10:27 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
    Dim oWSN:Set oWSN = CreateObject("WScript.Network")
  strCurrentUser= oWSN.UserName

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to david.rollins2)
 
 
Post #: 17
 
 RE: Notification script - 3/29/2006 2:35:53 AM   
  david.rollins2


Posts: 9
Score: 0
Joined: 3/22/2006
Status: offline
I'm sorry I didn't explain it very well. Using the LDAP. Instead of putting in the user name for the line:

Set objUser = GetObject(LDAP://cn=Ken Myer, ou=Finance, dc=fabrikam, dc=com)

I tried this:

Set objUser = GetObject(LDAP://cn=" & StrCurrentUser ", ou=Finance, dc=fabrikam, dc=com")

But it doesn't work I keep receiving the " Error:  Expected ')' "

(in reply to ebgreen)
 
 
Post #: 18
 
 RE: Notification script - 3/29/2006 2:39:59 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
The line you posted is missing some stuff.

Set objUser = GetObject("LDAP://cn=" & StrCurrentUser & ", ou=Finance, dc=fabrikam, dc=com")

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to david.rollins2)
 
 
Post #: 19
 
 RE: Notification script - 3/30/2006 1:26:20 PM   
  netxman

 

Posts: 116
Score: 0
Joined: 8/1/2005
Status: online
For question 1, I still using wscript.sleep method to loop.....:( 

And it seems lastLogonTimestamp is not available in Win2000.

(in reply to ebgreen)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Notification script Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts