Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  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 log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
CES 2009: Ballmer Announces Windows 7, Windows Live, Live Search Milestones

During his first-ever Consumer Electronics Show (CES) 2009 keynote address last night in Las Vegas, Microsoft CEO Steve Ballmer announced the pending public availability of a feature-complete Windows 7, the final version of Windows Live Essentials, and ...

Command Prompt Tricks

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

10 Reasons to Deploy Windows Vista

The decision to upgrade your XP systems to Vista is simple when you consider features such as easier backup, a great desktop search, and vastly improved security options. ...


Active Directory (AD) Whitepapers Sustainable Compliance: How to reconnect compliance, security and business goals

Managing Unix/Linux with Microsoft System Center Operations Manager 2007 Cross Platform Extensions Beta

Addressing the Insider Threat with NetIQ Security and Administration Solutions

Related Events Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

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

Windows 2003: Active Directory Administration Essentials

Related Active Directory (AD) Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing