require 'win32api'
Win32API.new('user32', 'OpenClipboard', ['I'], 'I').Call(0)
ghandle=Win32API.new('user32', 'GetClipboardData', ['I'], 'I').Call(1)
gdata=Win32API.new('kernel32', 'GlobalLock', ['I'], 'P').Call(ghandle)
tdata=gdata.to_s.sub(/(?<=search\?).+&(?=q=)/,"").sub(/&.*$/,"")+"\0"
Win32API.new('kernel32', 'GlobalUnlock', ['I'], 'I').Call(ghandle)
shandle = Win32API.new('kernel32', 'GlobalAlloc', 'II' ,'I').call(0x42,tdata.length)
sdata=Win32API.new('kernel32', 'GlobalLock', ['I'], 'P').call(shandle)
Win32API.new('msvcrt', 'memcpy', 'IPI', 'I').call(sdata,tdata,tdata.length)
Win32API.new('user32', 'EmptyClipboard', []).call()
Win32API.new('user32', 'SetClipboardData', 'II', 'I').call(1,shandle)
Win32API.new('user32', 'CloseClipboard', []).Call()
hはどうよ?