Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby & WMI (win32ole)

Reply
Thread Tools

Ruby & WMI (win32ole)

 
 
Nicholas Calvert
Guest
Posts: n/a
 
      06-17-2008
Hi guys,

First off, hello New to the community, looks very helpful and active
indeed...

As i say, I am new to Ruby and am trying to port some WMI Powershell
code over – I am not having much luck... My goal is to automate Hyper-V
on Windows 2008, as an example at a very simple level in powershell I
can do:

## Define variable for getting VSMS class
$VSMS = get-wmiobject MSVM_VirtualSystemManagementService -namespace
"root\virtualization"
## Then call a method on that class like this. Definevirtualsystem is
the method in question, I call it with no parameters.
$VSMS.definevirtualsystem()

I have tried two libarys in Ruby, win32ole and ruby-wmi. The synatx for
ruby-wmi confused me the most, so can only post a (kind of) working
example with win32ole:

require 'win32ole'
wmi =
WIN32OLE.connect("winmgmts:\\\\localhost\\root\\vi rtualization:Msvm_VirtualSystemManagementService")
wmi.ExecMethod(DefineVirtualSystem())

... this gives me the following error:
test.rb:4: undefined method `DefineVirtualSystem' for main:Object
(NoMethodError)

Also one of the tricks with WMI is to get the XML output of a class,
change the settings and squirt it back.

Using the previous example, i could do:

$VSMS.psbase.gettext(1)

...to give myself the raw XML. Is there an easy way to do this in Ruby?

Any pointers would be greatly appreciated.

Cheers,

Nick
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Masaki Suketa
Guest
Posts: n/a
 
      06-18-2008
Hello,
Nicholas Calvert wrote:
> I have tried two libarys in Ruby, win32ole and ruby-wmi. The synatx for
> ruby-wmi confused me the most, so can only post a (kind of) working
> example with win32ole:
>
> require 'win32ole'
> wmi =
> WIN32OLE.connect("winmgmts:\\\\localhost\\root\\vi rtualization:Msvm_VirtualSystemManagementService")
> wmi.ExecMethod(DefineVirtualSystem())


I have not used Powershell, so I'm not sure, but
How about the following script?
wmi.ExecMethod('DefineVirtualSystem')

Regards,
Masaki Suketa

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] ruby-wmi 0.2.2 Released Gordon Thiesfeld Ruby 0 01-14-2008 10:19 PM
WMI usage in Ruby to get file size, beginners question Gaius Bonus Ruby 2 11-30-2006 05:59 PM
Ruby and WMI timgerrlists Ruby 6 11-22-2005 03:36 AM
Ruby with WMI but that is not the problem. happy-jack Ruby 3 11-08-2005 09:40 PM
Ruby.exe crashing with WIN32OLE WMI example? yonatan Ruby 0 01-06-2004 07:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57