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

Logoff Script

Status
Not open for further replies.

dragonslayer49

IS-IT--Management
Nov 9, 2006
3
US
Do you know where I can find a log off script which will automatically logoff a user after certain time limit.

Your help will be greatly appreciated.
 
What if you made a scheduled task and had it execute when the computer was idle? You could call shutdown.exe to force the logoff....not necessarily a vbscript, though you could use one to take care of some of this for you....short answer...nothing easy or straight forward to accomplish what you want....and similar questions have been asked before and many have given their ideas about how to handle something like this.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
You will need to use a login script to do this so you can start a countdown timer. Then you can use WMI to force loggoff. The trick is using DateAdd to figure out the desired logoff time. Change the [red]red[/red] values for your desired session length.

Code:
[green]
'==========================================================================
'
' NAME: TimedLogoff.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor 
' COPYRIGHT: (c) 2008 All Rights Reserved
' DATE  : 10/20/2008
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
' COMMENT: 
'          
'
'==========================================================================
[/green]
On Error Resume Next
Const FORCE    = 4

SessionAllowedHours = [red]2[/red] [green]'hours[/green]
SessionAllowedMinutes = [red]30[/red][green]'minutes[/green]

LogonTime = Now
LogoffTime = DateAdd("h",SessionAllowedHours, LogonTime)
LogoffTime = DateAdd("n",SessionAllowedMinutes, LogoffTime)
WScript.Echo "You will be automatically logged off at:" & LogoffTime

Do While Now < LogoffTime
	WScript.Sleep 300
Loop
[green]
'Time to log off
[/green]
mname = "."
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & mname).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each OpSys In OpSysSet
	OpSys.Win32Shutdown FORCE
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top