9x下SystemParametersInfo可以禁止ctrl+alt+del,为什么还要用vxd
2k下不用vxd的方法我的主页www.8421.org有
不过我还是给你一个2k下动态加载驱动程序的代码,9x下差不多,不过我现在只有c代码:
program DogInst;
uses
Windows, SysUtils, WinSvc;
{$R *.res}
procedure ShowError(sError: string);
begin
MessageBox(0, PChar(sError), '安装错误', MB_OK or MB_ICONSTOP);
end;
function GetLastErrorMessage: string;
var
pMsgBuf: PChar;
begin
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM,
nil, GetLastError(),
GetSystemDefaultLangId,
@pMsgBuf, 0, nil);
Result := pMsgBuf;
LocalFree(HLocal(pMsgBuf));
end;
var
OSStyle: Integer;
m_currentDir, cur_windir, cur_sysdir: string;
procedure init;
var
osver: OSVERSIONINFO;
str: array[0..MAX_PATH] of Char;
begin
m_currentDir := ExtractFilePath(ParamStr(0));
if GetWindowsDirectory(str, SizeOf(str)) = 0 then
raise Exception.Create('GetWindowsDirectory 调用失败');
cur_windir := string(str);
if GetSystemDirectory(str, SizeOf(str)) = 0 then
raise Exception.Create('GetSystemDirectory 调用失败');
cur_sysdir := string(str);
OSStyle := 0;
osver.dwOSVersionInfoSize := SizeOf(OSVERSIONINFO);
GetVersionEx(osver);
case osver.dwPlatformId of
VER_PLATFORM_WIN32_WINDOWS:
if osver.dwMinorVersion = 0 then
OSStyle := 1 // Windows 95
else if osver.dwMinorVersion > 0 then
OSStyle := 2; // Windows 98
VER_PLATFORM_WIN32_NT:
if osver.dwMajorVersion = 5 then
OSStyle := 3 // Windows 2000
else
OSStyle := 4; // Windows NT 4.0 or below
else
Exception.Create('不支持该操作系统论');
end;
end;
procedure m_Copy(const FName: string);
var
b1: Boolean;
wAttr: DWORD;
FNew, FExisting: string;
begin
FExisting := m_currentDir;
if (OSStyle = 1) or (OSStyle = 2) then
FExisting := m_currentDir + 'win9x/' + FName
else if OSStyle = 3 then
FExisting := m_currentDir + 'win2000/' + FName
else if OSStyle = 4 then
FExisting := m_currentDir + 'winnt4/' + FName;
FNew := cur_sysdir + '/' + FName;
b1 := CopyFile(PChar(FExisting), PChar(FNew), FALSE);
if not b1 and (GetLastError = 5) then
begin
wAttr := GetFileAttributes(PChar(FNew));
wAttr := wAttr and not FILE_ATTRIBUTE_READONLY;
SetFileAttributes(PChar(FNew), wAttr);
b1 := CopyFile(PChar(FExisting), PChar(FNew), FALSE);
end;
if not b1 then
raise Exception.Create('复制 ' + FExisting + ' 到 ' + cur_sysdir + ' 失败');
end;
procedure inst2k;
const
DriverName = 'Mhdrv';
HOSTName = 'Hostnt';
var
d_driver: string;
schService: SC_HANDLE;
serviceStatus: SERVICE_STATUS;
SchSCManager: SC_HANDLE;
p: PChar;
dwTag: DWORD;
begin
schSCManager := OpenSCManager(nil, // machine (NULL == local)
nil, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
);
if schSCManager = 0 then
raise Exception.Create('调用01失败');
schService := OpenService (schSCManager, DriverName, SERVICE_ALL_ACCESS);
if schService <> 0 then
begin
if ControlService(schService, SERVICE_CONTROL_STOP, serviceStatus)
or ControlService(schService, SERVICE_CONTROL_STOP, serviceStatus) then
begin
while(QueryServiceStatus(schService, serviceStatus)) do
if(serviceStatus.dwCurrentState = SERVICE_STOP_PENDING) then
Sleep(1000)
else
Break;
end;
if not DeleteService(schService) then
ShowError('出现错误001:' + GetLastErrorMessage);
CloseServiceHandle(schService);
end;
schService := OpenService (schSCManager, HOSTName, SERVICE_ALL_ACCESS);
if schService <> 0 then
begin
if ControlService(schService, SERVICE_CONTROL_STOP, serviceStatus)
or ControlService(schService, SERVICE_CONTROL_STOP, serviceStatus) then
begin
while(QueryServiceStatus(schService, serviceStatus)) do
if(serviceStatus.dwCurrentState = SERVICE_STOP_PENDING) then
Sleep(1000)
else
Break;
end;
if not DeleteService(schService) then
ShowError('出现错误003:' + GetLastErrorMessage);
CloseServiceHandle(schService);
end;
d_driver := cur_sysdir;
cur_sysdir := cur_windir;
cur_sysdir := cur_windir + '/inf';
m_Copy('gsmhwdm.inf');
cur_sysdir := d_driver + '/drivers';
m_Copy('gsmhwdm.sys');
m_Copy('mhdrv.sys');
m_Copy('hostnt.sys');
dwTag := 2;
d_driver := cur_sysdir + '/mhdrv.sys';
schService := CreateService(SchSCManager, // SCManager database
DriverName, // name of service
DriverName, // name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_KERNEL_DRIVER, // service type
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL, // error control type
PChar(d_driver), // service's binary
'Extended base', // no load ordering group
@dwTag, // no tag identifier
'Parport'#0, // no dependencies
nil, // LocalSystem account
nil // no password
);
p := nil;
if schService <> 0 then
begin
CloseServiceHandle(schService);
if StartService(schService, 0, p) then Exit;
end;
schService := OpenService(SchSCManager,
DriverName,
SERVICE_ALL_ACCESS
);
if schService = 0 then
raise Exception.Create('调用25失败');
if not StartService(schService, 0, p) then
raise Exception.Create('调用26失败');
CloseServiceHandle(schService);
//OPEN-HOSTID--------------------
d_driver := cur_sysdir + '/hostnt.sys';
schService := CreateService(SchSCManager, // SCManager database
HOSTName, // name of service
HOSTName, // name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_KERNEL_DRIVER, // service type
SERVICE_AUTO_START, // start type
SERVICE_ERROR_NORMAL, // error control type
PChar(d_driver), // service's binary
'Extended base', // no load ordering group
@dwTag, // no tag identifier
nil, // no dependencies
nil, // LocalSystem account
nil // no password
);
if schService <> 0 then
begin
CloseServiceHandle(schService);
if StartService(schService, 0, p) then Exit;
end;
schService := OpenService(SchSCManager,
HOSTName,
SERVICE_ALL_ACCESS
);
if schService = 0 then
raise Exception.Create('调用27失败');
if not StartService(schService, 0, p) then
raise Exception.Create('调用28失败');
CloseServiceHandle(schService);
CloseServiceHandle(SchSCManager);
end;
begin
try
init;
inst2k;
except
on E: Exception do
ShowError(E.Message + ':' + GetLastErrorMessage);
end;
end.
另一个动态加载vxd的c例子见:
http://www.sysinternals.com/ntw2k/source/regmon.shtml