program AdminCMD;

{$APPTYPE CONSOLE}

uses
Windows,
ShellApi,
SysUtils; function RunAsAdmin(const iExeName, iParam: String): Boolean;
var
SEI: TShellExecuteInfo;
begin
Result := False; if (CheckWin32Version()) then
begin
ZeroMemory(@SEI, SizeOf(SEI)); with SEI do
begin
cbSize := SizeOf(SEI);
Wnd := ;
fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
lpVerb := 'runas';
lpFile := PChar(iExeName);
lpParameters := PChar(iParam);
nShow := SW_SHOW;
end; Result := ShellExecuteEx(@SEI);
end;
end; var
CmdPath: String;
begin
CmdPath := StringOfChar(#, MAX_PATH);
ExpandEnvironmentStrings(
PChar('%ComSpec%'),
PChar(CmdPath),
Length(CmdPath)); CmdPath := Trim(CmdPath); RunAsAdmin(CmdPath, '');
end.

http://www.lsworks.net/article/99.html

05-11 13:32