Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

August 01, 2000 04:22 PM

2 Ways to Force Logoffs from the Command Line

Windows IT Pro
InstantDoc ID #9676
Rating: (0)
More useful tools from the Windows NT Resource Kit Supplement 4

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.

Related Content:

ARTICLE TOOLS

Comments
  • Gabby
    8 years ago
    Nov 12, 2004

    I have a windows 2000 environment and am trying to log off a user on a remote server using logoff.vbs. However, when I run the command,
    "cscript logoff.vbs /s \\\\ServerA /u UserA /w PasswordA /f"
    the use on the remote computer never gets logged off. I do get a message in the command window saying, "Loggin off current user on ServerA..." but nothing actually happens on ServerA. Would you be able to tell me what I maybe missing?
    Suppliment 4 of the NT 4 Resource Kit is installed.

    Thanks for your time.
    Gabby.

  • Mike G.
    8 years ago
    May 29, 2004

    All of Microsoft's Resource Kits are available online.
    This master index can be found here...

    http://www.microsoft.com/technet/itsolutions/reskits/rktmain.mspx

  • Mike
    8 years ago
    Mar 20, 2004

    Where's logoff.vbs? Read the first paragraph: "Microsoft Windows NT Server 4.0 Resource Kit Supplement 4". Probably have to order it off of Amazon or something. I found it for under 3 bucks. Of course, this article was written like 3 1/2 YEARS ago, so maybe Microsoft has the same script on a more current version of the disc. Good luck!

  • KIL
    8 years ago
    Jan 08, 2004

    LOGOFF.VBS NOT FOUND WHAT PATH IS NECESSARY IN XP'S ENVIRON... VARIABLES?

  • 9 years ago
    Nov 21, 2003

    logoff.vbs is not exists in system32. Where can i find it?

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.