改成动态还是不行:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,unitacl, StdCtrls,JwaWinSafer;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function testdllfunc():boolean;
var
DllHandle:THandle;
Dllfarproc:Tfarproc;
begin
result:=false;
//动态调用dll
DllHandle := LoadLibrary('advapi32.dll');
try
if DllHandle <> 0 then begin
Dllfarproc := GetProcAddress(DllHandle, 'SaferComputeTokenFromLevel'); //找函数名,大小写敏感
if Dllfarproc <> nil then begin
result:=true;
end;
end;
finally
FreeLibrary(DllHandle);
end;
end;
function dropme(RightLever: Integer; ApplicationName, CommandLine, CurrDir: String): DWORD;
var
hSaferLevel: DWORD;
hAuthzLevel: SAFER_LEVEL_HANDLE;
hToken: THandle;
si:STARTUPINFO;
pi: PROCESS_INFORMATION;
begin
Result := ERROR_SUCCESS;
hSaferLevel := SAFER_LEVELID_NORMALUSER;
hAuthzLevel := 0;
if (SaferCreateLevel(SAFER_SCOPEID_USER, SAFER_LEVELID_NORMALUSER, 0, @hAuthzLevel, nil)) then
begin
hToken := 0;
if (SaferComputeTokenFromLevel(
hAuthzLevel,
0,
@hToken,
0,
nil)) then
begin
ZeroMemory(@si, sizeof(STARTUPINFO));
si.cb := sizeof(STARTUPINFO);
si.lpDesktop := nil;
if (CreateProcessAsUser(hToken, PAnsiChar(ApplicationName), PAnsiChar(CommandLine),
nil, nil, False, CREATE_NEW_CONSOLE, nil, PAnsiChar(CurrDir), si, pi)) then
begin
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
end
else
Result := GetLastError;
end
else
Result := GetLastError;
SaferCloseLevel(hAuthzLevel);
end
else
Result := GetLastError;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if testdllfunc then
dropme(2, paramstr(0), '', ExtractFilePath(paramstr(0)));
end;
end.