logging off windows users remotely with ruby

G

Gian Holland

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
 
J

James Tucker

Gian said:
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 :D

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.
 
J

Jano Svitok

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top