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

auto logoff a user

Status
Not open for further replies.

sysadmin42

Technical User
May 6, 2005
138
Is there a way to log off a user at a specific time? (Without regard to the amount of time the user has been logged on) i.e. at 7:00 P.M., the computer warns the user and then logs off. (Warning would be nice, but not necessary.)

"Together we can make 'computer illiterate' a dirty word."
 
Sure - if you know what computer they are sitting at you can use the Shutdown command from a command prompt. You can also display a warning.
"shutdown -l" will log them off

type the following from a command prompt for more details:

shutdown /?



*****************************************
Your mouse has moved - reboot for changes to take effect
 
There are several ways to do this. You say that you want to log out a specific user....Is this in a domain setting? If so, you could always "Force Logoff when Logon hours expire" in Group Policy.
You could also utilize something like below to run on the users PC at a scheduled time:

Code:
strcomputer = "."
On Error Resume Next
	Dim colOS, oOS
	Set colOS = GetObject("winMgmts:").ExecQuery("Select * from Win32_OperatingSystem")
	For Each oOS In colOS
		oOS.Win32Shutdown 0
		If Err.Number Then oShell.Run LPath & "\logout.exe", 0, True
	Next

This was hastily put together, so if there are issues, let me know.
 
Ok, so I think I will go with the shutdown -l. Anyone know how to lock out a user from modifying a scheduled task- or have the server log off the remote system?? It does appear that you can shutdown a remote computer, but the -l switch cannot be used with the -m switch (remote system).

"Together we can make 'computer illiterate' a dirty word."
 
Not sure with shutdown.exe but Psshutdown doesn't need installing on the stations, you run the exe from the server so the scheduled task only exists on the server not the stations. This means only one task needs setting up and only people with access to the server can alter it.
 
Okay, as long as the scheduled task is run by an admin of the "remote" machine, you could add this to your scheduled tasks on the server:

Code:
strcomputer = "[red]Remoteuserscomputername[/red]"
On Error Resume Next
    Dim colOS, oOS
    Set colOS = GetObject("winMgmts:").ExecQuery("Select * from Win32_OperatingSystem")
    For Each oOS In colOS
        oOS.Win32Shutdown 0
        If Err.Number Then oShell.Run LPath & "\logout.exe", 0, True
    Next
Change the remarks in red to match the users computer name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top