Ver Mensaje Individual
  #4  
Antiguo 03-09-2016
dardusso23 dardusso23 is offline
Miembro
NULL
 
Registrado: jun 2016
Posts: 37
Reputación: 0
dardusso23 Va por buen camino
Hola! Yo solo lo que necesito seria un boton que al hacerle click ejecute como admin un programa. He usado el codigo de RunAsAdmin que publicaste pero me da un error de que no puede allar el archivo. Copio como lo hice para ver donde esta el error:

[delphi]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls,ShellAPI, sButton;
const
ProgramName = 'MiPrograma.exe';

type
TForm1 = class(TForm)
sButton1: TsButton;
procedure sButton1Click(Sender: TObject);

private

procedure RunAsAdmin( strParameters: String = 'OK'; Handle : HWND = 0);
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RunAsAdmin( strParameters: String;
Handle: HWND);
var
Info : TShellExecuteInfo;
begin

FillChar(Info, SizeOf(Info), 0);

Info.cbSize := SizeOf(Info);
Info.Wnd := Handle;
Info.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
Info.lpVerb := 'runas';
Info.lpFile := PChar(ProgramName);
Info.lpParameters := PChar(strParameters);
Info.nShow := SW_SHOWNORMAL;

if not ShellExecuteEx(@Info) then
RaiseLastOSError;
end;

procedure TForm1.sButton1Click(Sender: TObject);
begin
RunAsAdmin('MiPrograma.exe');
end;

end.

Muchas gracias

Última edición por dardusso23 fecha: 03-09-2016 a las 14:00:37.
Responder Con Cita