Skip to content

Instantly share code, notes, and snippets.

@nrk
Created June 25, 2009 19:35
Show Gist options
  • Save nrk/136104 to your computer and use it in GitHub Desktop.
Save nrk/136104 to your computer and use it in GitHub Desktop.
require 'win32/process'
process_info = Process.create(
:app_name => "notepad.exe",
:creation_flags => Process::DETACHED_PROCESS,
:process_inherit => false
)
close_handle = Win32API.new('kernel32', 'CloseHandle', 'L', 'L')
create_process = Win32API.new('kernel32', 'CreateProcess', 'PPPPLLLPPP', 'L')
startup_info = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].pack('LLLLLLLLLLLLSSLLLL')
process_info = [0,0,0,0].pack('LLLL')
created = create_process.call(
0, # lpApplicationName
"notepad.exe", # lpCommandLine
0, # lpProcessAttributes
0, # lpThreadAttributes
0, # bInheritHandles
0x08, # dwCreationFlags
0, # lpEnvironment
"C:/Temp/", # lpCurrentDirectory
startup_info, # lpStartupInfo
process_info # lpProcessInformation
)
close_handle.call(process_info[0,4].unpack('L').first)
close_handle.call(process_info[4,4].unpack('L').first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment