1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, jpeg;
type
TPatchCBT = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
function CreateProcessWithLogonW(
lpUsername : PWideChar;
lpDomain : PWideChar;
lpPassword : PWideChar;
dwLogonFlags : DWORD;
lpApplicationName : PWideChar;
lpCommandLine : PWideChar;
dwCreationFlags : DWORD;
lpEnvironment : Pointer;
lpCurrentDirectory : PWideChar;
Const lpStartupInfo : TStartupInfo;
Var lpProcessInfo : TProcessInformation):Bool;stdcall;external 'advapi32.dll';
const
LOGON_WITH_PROFILE = 1;
LOGON_NETCREDENTIALS_ONLY = 2;
var
PatchCBT: TPatchCBT;
lpsaProcess,
lpsaThread : PSecurityAttributes;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
AddrCmd : Array [0..255] Of Char;
ExitCode : DWord;
implementation
{$R *.dfm}
procedure runas(sUser, sDomain, sPassword, sExecutable : PWideChar);
var
wUsername, wDomain, wPassword, wApplicationName: PWideChar;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
wUsername := sUser ;
wDomain := sDomain;
wPassword := Spassword;
wApplicationName := PWideChar(sExecutable) ;
FillChar(StartupInfo, SizeOf(StartupInfo), 0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_SHOWNORMAL;
if not CreateProcessWithLogonW(wUsername,nil,wPassword,1,
wApplicationName,nil,CREATE_DEFAULT_ERROR_MODE,
nil,nil,StartupInfo,ProcessInfo) then
RaiseLastOSError; //En cas d'erreur, donne des détails sur l'erreur
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
wShowWindow := SW_HIDE;
end;
end;
procedure TPatchCBT.Button1Click(Sender: TObject);
begin
runas('Administrateur','','NoobEnDelphi', ExecuteCommand(BuildDosCommandStr('cacls /?'),TRUE);));
end;
procedure TPatchCBT.Button2Click(Sender: TObject);
begin
application.terminate;
end;
end. |
Partager