I want to make a batch file that logs off the user when opened

So, previously I had been using the following in a batch file,

Start
Timeout /t 3
shutdown /l

This worked just fine for what I needed it for. It logged the user out of Google, and after 3 seconds, the system.

For some reason, as of 5/8/19, this hasn't worked. It still logs the user out of chrome, but does not log them out of the system. Instead it just repeats this over and over until it is closed.

C:\Users\Class\Desktop>shutdown /l

I know this is probably something super simple that I am looking over, but It is really confusing me. Granted, I'm no professional by any means.

I have tried it on other systems, and even tried different variants of the shutdown command, /l, /r, and, /s.

The system has not been updated since 4/10/19. No one else has had the time to tamper with the system. What do.

4

1 Answer

Based on your comments,

I tried running it from a different location, and It worked just fine.

I suspect something has changed in your environment that is causing it to not work properly from this location. Multiple things come to mind, but leave some guesswork as to why you see the specific behavior that you do.

My guess is one of a few things:

  • You have a shortcut or file on your desktop called "timeout", or "shutdown." So, instead of your batch file running the executable command called shutdown, it is executing the file on your desktop.
  • You recently enabled folder redirection, and something strange is happening there.
  • Your PATH environment variable has changed, causing a file / shortcut called "timeout," or "shutdown," in a different location on your drive to execute rather than the proper one that is located usually in c:\windows\system32.

I think the most likely solution to solve this problem is to insure the right shutdown and timeout command is being run. To do so, use an absolute path instead of a relative path in your scripts.

Your final script should look like this:

start
%systemroot%\system32\timeout.exe /t 3
%systemroot%\system32\shutdown.exe /l

The environment variable %systemroot% resolves to where you have Windows installed which is typically c:\windows. Using an environment variable like this is a technique to make sure your batch file is portable and works properly on any Windows computer, instead of only ones that have Windows installed at C:\Windows.

This change to using absolute paths forces the batch file to run the specific commands located in the Windows folder.

One final note, adding the /f parameter to the shutdown command will ensure the logoff is forced by terminating any open applications that try to prevent the logoff or shutdown of the computer. This comes with a risk of data loss, if the user hasn't saved something.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like