Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


September 2000

2 Ways to Force Logoffs from the Command Line


RSS
Subscribe to Windows IT Pro | See More Active Directory (AD) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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.

End of Article



Reader Comments
where can i find the logoff.vbs???

j April 17, 2002


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

DB November 21, 2003


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

KIL January 08, 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!

Mike March 20, 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 G. May 29, 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.


Gabby November 12, 2004


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Active Directory (AD) Whitepapers Meeting Compliance Objectives in SharePoint

Email Controls and Regulatory Compliance

Related Events WinConnections and Microsoft® Exchange Connections

Troubleshooting Active Directory

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Active Directory (AD) eBooks The Essentials Series: Active Directory 2008 Operations

Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Windows 2003: Active Directory Administration Essentials

Related Active Directory (AD) Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement