From: Gordon Thiesfeld Date: 2008-04-21T22:49:46+09:00 Subject: Re: Accessing Windows actions(Shutdow.Restart) On Mon, Apr 21, 2008 at 1:25 AM, Raveendran Perumalsamy wrote: > Hi All, > > I want to access the windows functionalities such as Shut down, Restart, > Log off etc.. > > Please guide to me.. > > Because i tried win32OLE, Watir and few gems.. But still there is no > improvement to access those things. > > Awaiting reply. > > Regards, > P.Raveendran > RailsFactory,Chennai. > http://raveendran.wordpress.com > -- > Posted via http://www.ruby-forum.com/. > > Here are a few ways. You'll need admin privileges on any box you run it against. Using WMI via win32ole locally. LogOff = 0 ForcedLogOff = 4 Shutdown = 1 ForcedShutdown = 5 Reboot = 2 ForcedReboot = 6 PowerOff = 8 ForcedPowerOff = 12 require 'win32ole' wmi = WIN32OLE.connect("winmgmts:\\\\.\\root\\cimv2") list = wmi.execquery("Select * from Win32_OperatingSystem",nil,48) list.each do |item| item.win32Shutdown(LogOff) end Using ruby-wmi (gem install ruby-wmi) locally. require 'ruby-wmi' #you'll need the same constants as above host = 'computername' os = WMI::Win32_OperatingSystem.find(:first) os.win32shutdown(LogOff ) Using win32ole remotely. require 'win32ole' # constants computer_name = 'host' wmi = WIN32OLE.connect("winmgmts:\\\\#{computer_name}\\root\\cimv2") list = wmi.execquery("Select * from Win32_OperatingSystem",nil,48) list.each do |item| item.win32Shutdown(LogOff ) end Using ruby-wmi remotely. require 'ruby-wmi' # constants host = 'computername' os = WMI::Win32_OperatingSystem.find(:first, :host => host) os.win32shutdown(LogOff ) Gordon