预编译中如何判断操作系统(区分2k和xp) ( 积分: 100 )

  • 主题发起人 主题发起人 tianzhen
  • 开始时间 开始时间
T

tianzhen

Unregistered / Unconfirmed
GUEST, unregistred user!
程序在xp下正常,2k下即使不执行相关代码,一打开就出错:
无法定位程序输入点safercomputertokenfromlevel于动态链接库advapi32.dll

2k下可以不用这个函数的功能,但该怎么写才能不提示错误呢,谢谢。
 
你可以使用动态加载的方法来调用 这个函数的
 
改成动态还是不行:
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.
 
JwaWinSafer:
http://jedi-apilib.sourceforge.net/win32api_current.zip
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部