Asked
Updated
Viewed
63.3k times

Does anyone know a way to force users to log off via a batch file?

I want the user to log on to a workstation or server, once they logged in a script will run automatically. Once the script has run, I want to force the user to log out of the server or workstation.

add a comment
1

2 Answers

  • Votes
  • Oldest
  • Latest
Answered
Updated
shutdown -l

Put that in your batch file. 🙂 Sounds like an insult doesn't it? This assumes XP.

  • 0
    Thanks for the response. What is the -1 flag mean? I don't want to shutdown the server. I just want the user to be forced to logoff. — ljCharlie
  • 0
    -L is a "dash" then an "L" for logoff. That code font makes it look like a 1 🙂. In a command prompt you can just type "shutdown" and it'll give you the options that go along with it. For example, "shutdown -s" actually will shutdown your PC. — icyroadz
  • 0
    Thanks! I'll give that a try. — ljCharlie
  • 0
    This is the best result from google (many links I have went through). My boss refuses to let me link a gpo to our users OU, so I created a batch file to restart some computers. I would like to use shutdown -l, but this does not run in a batch file. Is there a missing switch? Edit: Sorry this works in a batch file, but only for a local computer, I would like to know how to batch this over RPC. — renegade X
add a comment
1
Answered
Updated

Just in case anyone else has run into a similar problem:

Server 2003 environment with thin clients as workstations. I have a particular thin client setup to run specific programs upon logon (active directory, environment tab). As such, they need to logoff once a day so the program can shut down gracefully and then log back on to start the programs back up again. I created a batch file that accomplishes all of this at once. Run the batch file as soon as the user logs on.

@echo off
sleep 20
cd "C:\Program Files\Test\"
start /max test.exe
sleep 86100
tskill test
sleep 5
shutdown -l

The thin client uses RDP to connect and the connection is set to auto logon.

add a comment
1