≡ Menu

logoff

Sometime it is necessary to reboot (or shutdown) windows server. Under UNIX or Linux you can use reboot / hal t/shutdown command via cron jobs or at command. But, when it comes to Windows server there is no built in command exist. Only Windows 2000 Resource Kit offers shutdown command line utility.

However, sysinternals has nifty utility called PsShutdown. It is a command-line utility similar to the shutdown utility from the Windows 2000 Resource Kit, but with the ability to do much more. In addition to supporting the same options for shutting down or rebooting the local or a remote computer, PsShutdown can logoff the console user or lock the console (locking requires Windows 2000 or higher). PsShutdown requires no manual installation of client software.

How do I schedule Windows Server Reboot / Shutdown?

You can download PsShutdown from sysinternals web site.

Store file on Windows server in folder. I use folder called C:\admutils. Next open windows command prompt (Start > Run > cmd) and use windows at command to schedule reboot:
c:> at 2:00am c:\admutils\psshutdown.exe -r -f -c -t 10
Above command will reboot system at 2am. If you want to shutdown system:
c:> at 1:00am c:\admutils\psshutdown.exe -s -f -c -t 10
Where,

  • -s: Shutdown windows server
  • -r: Reboot windows server
  • -f: Forces all running application to exit
  • -c: Allow the shutdown to by cancel by user
  • -t: Specifies the countdown in seconds until the shutdown

For more information read official psshutdown documentation. Read at command help by typing at /? command.

It is true that Gnome desktop provides nice facility to logoff, shutdown or restart computer with dialog. You can create a nice shortcut to avoid the GUI confirmation dialog box to speed up work.

(A) Shutdown computer
i) Right click on Desktop > Select Create Launcher
ii) Type the Command in text box “sudo /sbin/shutdown -h 0” and for rest of properties refer following figure:

iii) Click Close to save. Please note that only root will be able to shutdown system. However with the help of sudo it is possible that non-privileged can also shutdown the system (without password). Type following commands:
a) Login as root user

b) Type visudo command:
#visudo

c) Append following text of line, so that all commands will be excuted without password.
vivek localhost= NOPASSWD: /sbin/shutdown -h 0
vivek localhost= NOPASSWD: /sbin/reboot

By default, sudo requires that a user authenticate him or herself before running a
command. This behavior is modified with NOPASSWD flag i.e. shutdown and reboot command would allow user vivek run as root on the localhost as root without authenticating (password) himself

d)Save the file and replace command in above figure with sudo /sbin/shutdown -h now and close the dialog Launcher dialog box.

(B) Restart computer
i) Right click on Desktop > Select Create Launcher
ii) Type the Command in text box “sudo /sbin/restart” and for rest of properties refer following figure:

(C) Logoff Gnome

i) Right click on Desktop > Select Create Launcher
ii) Type the Command in text box “/usr/bin/gnome-session-save --kill” and for rest of properties refer following figure:

iii) Make sure you turnoff user logout dialog box. Type command OR Click on Applications > Desktop Preferences > Advanced > Sessions and clear the option box 'Prompt on logout' > Click close to save changes.

You can also use logoff script, to logoff KDE/Gnome desktop session. All these hacks should also work with FreeBSD or OpenSolaris desktop.