Jon A. Lambert
4/27/2005 5:53:00 AM
Jon A. Lambert wrote:
> You might use CreateProcess from Win32api.
> The PID is returned in the last parameter, the process_information
> structure.
> Then use that PID in calling OpenProcess to get the Handle to use
> when calling TerminateProcess.
Here's a bit of code that partly works. That is it does get the process id.
You'd have to look up all the actual values in the windows headers
for the options you want.
require 'Win32API'
createProcess =
Win32API.new("kernel32.dll","CreateProcess",'pplllllppp','L')
startupinfo = [ 68 ].pack("lx64")
procinfo = [ 0,0,0,0 ].pack("llll")
createProcess.call(nil,"write.exe", 0, 0, 1, 0, 0, "c:\\apps", startupinfo,
procinfo)
processid = procinfo.unpack("llll")[2]
puts processid
# works up to here
openProcess = Win32API.new("kernel32.dll","OpenProcess",'lll','L')
handle = openProcess.call(0, 0, processid)
puts handle
terminateProcess = Win32API.new("kernel32.dll","TerminateProcess",'ll','L')
terminateProcess.call(handle, 0)