Skip to content

Instantly share code, notes, and snippets.

@arton arton/gist:8251566
Created Jan 4, 2014

Embed
What would you like to do?
=begin
Copyright(c) 2008 arton
Usage of the works is permitted provided that this instrument is retained
with the works, so that any entity that uses the works is notified of this
instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
=end
require 'cstruct'
require 'dl/import'
module SuExec
extend DL::Importable
dlload 'shell32.dll'
extern 'int ShellExecuteExA(void *)'
ShellExecuteInfoA = C::Struct.define {
DWORD :cbSize;
ULONG :fMask;
HANDLE :hwnd;
PCSTRA :lpVerb;
PCSTRA :lpFile;
PCSTRA :lpParameters;
PCSTRA :lpDirecotry;
UINT :nShow;
HANDLE :hInstApp;
PVOID :lpIDList;
PCSTRA :lpClass
HANDLE :hkeyClass;
ULONG :dwHotKey;
HANDLE :hIcon;
HANDLE :hProcess;
}
def self.exec(prog, *params)
shellExecuteExA(ShellExecuteInfoA.new(ShellExecuteInfoA.size, 0, 0,
'runas', prog, params.join(' '), '',
1, 0, 0, nil, 0, 0, 0, 0).serialize)
end
end
if __FILE__ == $0
SuExec.exec('notepad.exe')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.