On average, I receive a letter a month asking whether a command-line tool is available to force a logoff. Until recently, I've known of no such tool. But the Microsoft Windows NT Server 4.0 Resource Kit Supplement 4 contains two: a compiled program, logoff.exe, and a VBScript routine, logoff.vbs, that does even more than logoff.exe does.
You can call logoff.exe from a batch file. Its syntax is
logoff \[/n\] \[/f\]
When you invoke logoff without options, logoff asks whether you really want to log off and accepts a y (yes) or n (no) response. When you type y in response, NT logs you off unless an application has unsaved data, in which case the application stops the logoff process and asks you to verify that you really want to log off without saving your data. Clearly, a logoff command that requires confirmation isn't much help in a batch file. Enter the /n and /f options.
If you specify the /n option, logoff doesn't present its confirmation prompt. However, if you have open and unsaved data, your applications still ask whether you really want to log off. You might want to retain those application prompts, because batch scripts that kick users off their machines and lose their data make for lousy administrator-user PR. But if you don't need the application prompts, you can use the /f option to force the logoff.
Logoff.exe is convenient because it's a standalone executable binary. But if you want to log off a user at a remote machine, you'll need to use the VBScript routine. You'll find both logoff.vbs and logoff.exe in the resource kit directory. So, when you type logoff from a command prompt in the resource kit directory, you'll execute logoff.exe, not logoff.vbs. (The command shell always looks for .exe files before it looks for script files.) To force the shell to run the VBScript routine, type the entire filename (i.e., logoff.vbs) at the command line.
Because Microsoft based logoff.vbs on Web-Based Enterprise Management (WBEM), you can use this script to force logoffs on remote machines. But the target machine on which you want to force the logoff must have WBEM installed. All Windows 2000 systems include WBEM; for NT machines, you can download it from Microsoft's Web site for free or get the WBEM base code from the resource kit.
The logoff.vbs syntax is
logoff.vbs /s <servername> /u <username> /w <password> /f
You use the /s option to execute the script on a particular server. You can pass an administrative account name and password to that server with the /u and /w options, respectively. The /f option forces all applications to close. Logoff.vbs doesn't have anything like logoff .exe's /n option because logoff.vbs never prompts with an "Are you sure?" message.
Suppose I want to force the user sitting at a server named \\uptown to log off. Suppose also that I have an administrative account named BigGuy on \\uptown, and BigGuy's password is stingray. I could force a logoff with the command
logoff.vbs /s \\uptown /u bigguy /w stingray /f
Embedding an administrative account name and password in a batch file isn't often a good idea, so you might be a bit limited in what you can do remotely with logoff.vbs. But if you ever do need to do a logoff from a batch file, you'll appreciate that logoff.vbs is readable code. You can read the VBScript file, then use the same technique to include logoff functionality in your own batch script. You've just got to love seeing Microsoft embrace open source.