Logging off windows users remotely with ruby

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

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 :smiley:

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.

On 6/1/07, James T. [email protected] 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 :smiley:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs