Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Log on script to log off user after log on for 30 mins

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Log on script to log off user after log on for 30 mins
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Log on script to log off user after log on for 30 mins - 12/28/2005 4:19:19 PM   
  azmantek

 

Posts: 14
Score: 0
Joined: 3/15/2005
From:
Status: offline
To whom it may concern,

I would like to have a log on script that log off user after he logs on for 30 mins.

I was thinking of having it to check group membership first and then start the count down timer to forcefully log that user off.

Please help. Happy holidays and Thank you very much.

Regards,
 
 
Post #: 1
 
 RE: Log on script to log off user after log on for 30 mins - 12/28/2005 11:06:36 PM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
Hi, i´ve cut out the following parts from a bigger script i once made, so i havnt tried the code myself, but it should atleast point you in the right direction for getting the "logout" part of ur script. You can prolly clean it up a lil as well. Add a timer in the beginning of the script and/or make some popups waring about "5 mins left" and you  should have a good start.


      

Hope it helps!

/CM

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to azmantek)
 
 
Post #: 2
 
 RE: Log on script to log off user after log on for 30 mins - 12/29/2005 5:18:26 AM   
  azmantek

 

Posts: 14
Score: 0
Joined: 3/15/2005
From:
Status: offline
Hi Matt,

Thank you very much for your help. I'm still very new with VBScript, so this is kinda over head for me. I want to help out a friend. Would you please help me with a full script? or if you are busy, please point me to a good place where I can start learning VBScript as quick as I can. Thank you.  I really appreciate your kindness.

Regards,

(in reply to crazymatt)
 
 
Post #: 3
 
 RE: Log on script to log off user after log on for 30 mins - 12/29/2005 6:58:14 AM   
  DocHolliday

 

Posts: 3
Score: 0
Joined: 12/29/2005
Status: offline
Here, try this one.  Please, test it first!

'
' ***********************************************************************
' *
' * LogoffIn30 - Logs off the current user in 30 minutes
' * John Holliday - 12/29/2005 - 1.0
' * ChangeAuthorName - DateOfChange - IteratedVersionNumber
' *
' ***********************************************************************
'
Option Explicit


Public gobjWshShell
 
Sub ScriptInit()
Set gobjWshShell = CreateObject("WScript.Shell")
End Sub


Function Sleep(lintNumOfSeconds, lblnUseMilliseconds)
' Put False as the second argument to use standard seconds.
' Put True to use milliseconds.
If lblnUseMilliseconds = False Then
 lintNumOfSeconds = lintNumOfSeconds * 1000
End If
WScript.Sleep lintNumOfSeconds
End Function


Sub ShutDown(lintShutdownType)
Dim strComputer
Dim OpSys
Dim OpSysSet
strComputer = "."
If lintShutDownType = "" then
 lintShutDownType = 4
End If
Set OpSysSet = GetObject("winmgmts:{(Debug,Shutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each OpSys in OpSysSet
 OpSys.win32Shutdown(lintShutdownType)
Next
' The numbers in the Decimal column are for the lintShutDownType variable.
' Action  Decimal  Binary
' Logoff   0  0000
' Reboot   2  0010
' Force Logoff  4  0100
' Force Reboot  6  0110
' Powerdown   8  1000
' Force Powerdown 12  1100
End Sub


Sub RunFor30()
 On Error Resume Next
Dim lblnIsDone
Dim lintNumMinutes
lintNumMinutes = 0
   Do
  lblnIsDone = False
       Sleep 60, False
       lintNumMinutes = lintNumMinutes + 1
 Select Case lintNumMinutes
  Case 25
   gobjWshShell.Popup "Warning!" & vbCrLf & vbCrLf & "This workstaion will be logged off in 5 minutes!" & vbCrLf & "Please save your data and close any open applications." & vbCrLf & "This box will close in 15 seconds.", 15, "Logoff Warning", vbExclamation + vbOKOnly + vbSystemModal
  Case 30
   lblnIsDone = True
   ShutDown 4       
  Case Else
   ' Do nothing
 End Select
   Loop Until lblnIsDone = True
End Sub


' Processing starts here

ScriptInit
RunFor30
WScript.Quit


' ***************

That's the end of the script.  Remember that the "gobjWshShell.Popup" line is all on ONE line, not two.  Let me know if it works.

- Doc

(in reply to azmantek)
 
 
Post #: 4
 
 RE: Log on script to log off user after log on for 30 mins - 12/29/2005 7:54:31 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi DocHolliday,

I hope you won't mind being called 'a fast gun'! I do like your script/style. Using "Public"
instead of simple "Dim" to mark global variables, stating variable types explicitly, splitting
the script in reusable, independent parts, explaining the used numeric constants - I'm
very impressed.

So don't take my following questions as criticism - I just want to lure you into a discussion
about "VBScript - Best Practices".

  1. Why is gobjWshShell global - it's used in RunFor() only?
  2. Why do you use "lblnUseMilliseconds = False" or "lblnIsDone = True"?
  3. Woudn't RunFor() be more usefull if given the MinutesToRun as a parameter?
  4. Why did you code the action to do after the N minutes into RunFor()?

(in reply to DocHolliday)
 
 
Post #: 5
 
 RE: Log on script to log off user after log on for 30 mins - 12/29/2005 5:05:26 PM   
  azmantek

 

Posts: 14
Score: 0
Joined: 3/15/2005
From:
Status: offline
Thank you very much John. The scripts work perfectly. I do appreciate your help.

Regards,

(in reply to DocHolliday)
 
 
Post #: 6
 
 RE: Log on script to log off user after log on for 30 mins - 12/29/2005 6:54:36 PM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
quote:

ORIGINAL: DocHolliday

Here, try this one.  Please, test it first!



Good job Doc and welcome here!

Dont forget to use the "code" tags to enbedd your code a separate window within the post (its the "<%" symbol next to the font size when you are creating a new post)

Regards Matt

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to DocHolliday)
 
 
Post #: 7
 
 
 
  

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 >> Log on script to log off user after log on for 30 mins Page: [1]
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