unit Unit2;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls, ShellAPI;
type
TForm2 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure RunAsExec(hWnd: HWND; aFile:
string; aParameters:
string);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.RunAsExec(hWnd: HWND; aFile:
string; aParameters:
string);
var
SEI: TShellExecuteInfo;
begin
FillChar(SEI, SizeOf(SEI), 0);
SEI.cbSize := sizeof(SEI);
SEI.Wnd := hWnd;
SEI.fMask := SEE_MASK_NOCLOSEPROCESS;
SEI.lpVerb := '
runas';
SEI.lpFile := PChar(aFile);
SEI.lpParameters := PChar(aParameters);
SEI.nShow := SW_SHOWNORMAL;
if not ShellExecuteEx(@SEI)
then
RaiseLastOSError;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
DateiName:
string;
Parameter:
string;
begin
DateiName := '
C:\temp\test.exe';
Parameter := '
' + '
administrator' + '
' + '
password';
RunAsExec(Application.Handle, DateiName, Parameter);
end;
end.