# In need of help. Win32Ole objWMIService.Create?

**URL:** <https://www.ruby-forum.com/t/in-need-of-help-win32ole-objwmiservice-create/49639>\
**Category:** Ruby\
**Created:** [December 7, 2005, 4:08am UTC](https://www.ruby-forum.com/t/in-need-of-help-win32ole-objwmiservice-create/49639 "2005-12-07T04:08:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [December 7, 2005, 4:08am UTC](https://www.ruby-forum.com/t/in-need-of-help-win32ole-objwmiservice-create/49639/1 "2005-12-07T04:08:42Z")

</div>

objWMIService.Create takes a parameter which is set to the pid of a  
given process…

IE:

------start\_process.vbs-----  
strComputer = “.”  
Set objWMIService = GetObject(“winmgmts:\.\root\cimv2:Win32\_Process”)  
Error = objWMIService.Create(“cmd /c exit 10”, null, null, pid)  
Wscript.Echo pid  
------/start\_process.vbs-----

While trying to incorporate this within ruby, I ended up with  
something of the like:

------start\_process.rb---------  
require ‘win32ole’  
pid = nil  
objWMIService =  
WIN32OLE.connect(“winmgmts:\\.\root\cimv2:Win32\_Process”)  
error = objWMIService.Create(“notepad”, nil, nil, pid)  
puts pid # nil  
------/start\_process.rb---------

How can I set a variable equal to the pid value just as the vb script  
does?

I did find an object in ObjectSpace that has the “notepad” command and  
displays the PID:

ObjectSpace.each\_object(Array) { |x|  
p x if x[0] == “notepad”  
}

[“notepad”, nil, nil, nil]  
[“notepad”, -2147352572, -2147352572, 268]  
=\> 1363  
irb(main):008:0\>

Any ideas?

---

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [December 7, 2005, 4:18pm UTC](https://www.ruby-forum.com/t/in-need-of-help-win32ole-objwmiservice-create/49639/2 "2005-12-07T16:18:16Z")

</div>

Hi,

x1 asked:

> objWMIService.Create takes a parameter which is set to the pid of a  
> given process…  
> …  
> How can I set a variable equal to the pid value just as the vb script  
> does?  
> …  
> I did find an object in ObjectSpace that has the “notepad” command and  
> displays the PID:

The \_invoke method takes an array of values and an array of types. Your  
interesting ObjectSpace array looks like the array of values you might  
get  
back if you gave \_invoke the dispid of the method,  
[“notepad”,nil,nil,nil],  
and the types. But you can’t reflect on Create or other Win32\_Process  
methods to get that dispid or those types.

This is only a partial answer, but for some situations, the win32-utils  
project and win32-process in particular may prove an adequate  
replacement  
for this function. win32-process provides Process.create which wraps  
Win32’s  
CreateProcess() and returns a PID. It gives you fork (more or less),  
wait  
and kill as well.

Cheers,  
Dave
