# Logging off windows users remotely with ruby

**URL:** <https://www.ruby-forum.com/t/logging-off-windows-users-remotely-with-ruby/105653>\
**Category:** Ruby\
**Created:** [June 1, 2007, 2:20am UTC](https://www.ruby-forum.com/t/logging-off-windows-users-remotely-with-ruby/105653 "2007-06-01T02:20:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [June 1, 2007, 2:20am UTC](https://www.ruby-forum.com/t/logging-off-windows-users-remotely-with-ruby/105653/1 "2007-06-01T02:20:31Z")

</div>

We have about 11 windows 2k/xp boxes that I would like to force a logoff  
remotely.

Any help? I know it can be done with vbscript and wmi, but I really  
really want to accomplish this using some ruby as I am trying to  
introduce more of it in our company

---

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [June 1, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/logging-off-windows-users-remotely-with-ruby/105653/2 "2007-06-01T15:01:00Z")

</div>

Gian H. wrote:

> We have about 11 windows 2k/xp boxes that I would like to force a logoff  
> remotely.
> 
> Any help? I know it can be done with vbscript and wmi, but I really  
> really want to accomplish this using some ruby as I am trying to  
> introduce more of it in our company

All you have to do is use rundll32.exe calling the relevant function in  
user32.dll. I don’t remember specifically what the logoff function is  
called on XP, I know that it used to be:

rundll32.exe user32.dll ExitWindowsEx

This function still remains in user32.dll, but seems to do very little -  
maybe I’m missing some arguments.

I have seen a number of tools missing from XP Home edition, so the  
following may work on professional only:

shutdown -l (-f)

If you want to run these commands on a remote machine, you will need to  
authenticate with IPC$ on the machine first:

net use \machine\IPC$ /user:username (/savecred)

You will be prompted for a password with the above. On XP Pro, you can  
save these in Control Panel -\> Users, under “Manage my network  
passwords”.

You can then use the ‘at’ command to run a command on a remote machine  
at a particular time, e.g.

at \machine 14:00 “shutdown -l -f”

You can also schedule these using the at command, and query remotes  
using “at \remote”.

There is no substitute for native interfaces 😃

On the ‘using ruby’ front, you could ensure that this happens on the  
machines by having ruby parse the output of the at command for you. You  
could also attempt the approach of running drb sessions on each host,  
however, given that the system is already running an RPC stack built for  
the purpose, I would say this would be a waste of time.

Enjoy,

raggi.

---

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [June 1, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/logging-off-windows-users-remotely-with-ruby/105653/3 "2007-06-01T16:59:24Z")

</div>

On 6/1/07, James T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> All you have to do is use rundll32.exe calling the relevant function in user32.dll. I don’t remember specifically what the logoff function is called on XP, I know that it used to be:
> 
> There is no substitute for native interfaces 😃
> 
> On the ‘using ruby’ front, you could ensure that this happens on the machines by having ruby parse the output of the at command for you. You could also attempt the approach of running drb sessions on each host, however, given that the system is already running an RPC stack built for the purpose, I would say this would be a waste of time.

Additionally you can use WMI through Win32OLE, and issue the commands  
that way.
