From: Bryan Richardson Date: 2008-08-13T07:31:45+09:00 Subject: Re: WIN32OLE -- cannot terminate Excel process Weird... maybe ProcessID is an application-by-application type thing. On Tue, Aug 12, 2008 at 3:57 PM, djlewis wrote: > On Aug 12, 4:41 pm, Bryan Richardson wrote: >> require 'win32ole' >> >> excel = WIN32OLE.new 'excel.Application' >> >> puts excel.ProcessID >> >> -- >> Bryan >> >> >> >> > Yup, thought of that, and will do it if I can't figure out how to >> > terminate the process cleanly. So, how do I get the ProcessID? >> >> > Thanks. --David. > > OK, thanks. Process.kill works nicely, if I know the processID. But > excel.ProcessID does not fly. In a casual browse through excel's > ole_methods, I don't see anything that would obviously do the trick. > > I could always looks through the process, thus... > > wmi = WIN32OLE.connect("winmgmts://") > processes = wmi.ExecQuery("select * from win32_process where > commandline like '%excel.exe\"% /automation %'") > for process in processes do > Process.kill( 'KILL', process.ProcessID.to_i) > end > > That would kill ~all~ automation instances of Excel, which may be what > I want, but maybe not. So, I still don't see an easy way to find the > specific ProcessID, that is, without doing queries before and after > WIN32OLE.new 'excel.Application' and see what new excel process just > appeared. > > --David. > > Thanks. --David. > >