Created
January 4, 2014 04:12
-
-
Save arton/8251566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=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