阅读:1759回复:13
可不可以这样使用驱动程序?
我想这样使用驱动程序:不用安装,也不必在注册表中加入任何键值,就可以在应用程序里打开它的句柄,然后象其它的驱动一样正常读写。有没有可能呀?如果可能,应该怎么做?
|
|
最新喜欢:abc009... |
沙发#
发布于:2002-10-06 15:52
BOOL LoadDeviceDriver( const TCHAR * Name, const TCHAR * Path,
HANDLE * lphDevice, PDWORD Error ) { SC_HANDLE schSCManager; BOOL okay; schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); // Remove previous instance RemoveDriver( schSCManager, Name ); // Ignore success of installation: it may already be installed. InstallDriver( schSCManager, Name, Path ); // Ignore success of start: it may already be started. StartDriver( schSCManager, Name ); // Do make sure we can open it. okay = OpenDevice( Name, lphDevice ); *Error = GetLastError(); CloseServiceHandle( schSCManager ); return okay; } BOOL InstallDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName, IN LPCTSTR ServiceExe ) { SC_HANDLE schService; // // NOTE: This creates an entry for a standalone driver. If this // is modified for use with a driver that requires a Tag, // Group, and/or Dependencies, it may be necessary to // query the registry for existing driver information // (in order to determine a unique Tag, etc.). // schService = CreateService( SchSCManager, // SCManager database DriverName, // name of service DriverName, // name to display SERVICE_ALL_ACCESS, // desired access SERVICE_KERNEL_DRIVER, // service type SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type ServiceExe, // service\'s binary NULL, // no load ordering group NULL, // no tag identifier NULL, // no dependencies NULL, // LocalSystem account NULL // no password ); if ( schService == NULL ) return FALSE; CloseServiceHandle( schService ); return TRUE; } BOOL StartDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName ) { SC_HANDLE schService; BOOL ret; schService = OpenService( SchSCManager, DriverName, SERVICE_ALL_ACCESS ); if ( schService == NULL ) return FALSE; ret = StartService( schService, 0, NULL ) || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING || GetLastError() == ERROR_SERVICE_DISABLED; CloseServiceHandle( schService ); return ret; } 这是从FileMon中摘录下来的 |
|
|
板凳#
发布于:2002-10-07 17:00
好的,先试试。
|
|
地板#
发布于:2002-10-07 17:16
这样会有在注册表中生成键值的。CreateService ?
其中的RemoveDriver 是为系统提供的吗? :( |
|
|
地下室#
发布于:2002-10-08 09:51
这个是ntddk提供的啊。 :)
|
|
|
5楼#
发布于:2002-10-14 18:04
为什么我打开时总是失败?
BOOL LoadDeviceDriver( const TCHAR * Name, const TCHAR * Path, HANDLE * lphDevice, PDWORD Error ) 这里的Name和Path应该是什么样的? Name要不要带.sys? 而这个Path要不要连整个驱动程序一起给出? |
|
6楼#
发布于:2002-10-14 18:26
我终于打开了
但是又有一个问题出来了 我调用Load后,也调用了Unload,但是再次调用Load时就失败了,关闭应用程序后再调用Load又可以了。 这是为什么? |
|
7楼#
发布于:2002-10-14 20:01
我知道是什么原因了
谢谢 不过我觉得奇怪的是 其中的Path不是Path,而应该是Path + Name,这样才能正确打开 |
|
8楼#
发布于:2002-10-14 21:00
我又错了
从表面上来看,好象是打开正确了,但是事实上,并没有打开 因为我用DeviceIoControl来对其控制,一点作用也没有 应该怎么办? |
|
9楼#
发布于:2002-10-14 21:11
// NOTE: We\'re making an assumption here that the driver
// has created a symbolic link using it\'s own name // (i.e. if the driver has the name \"XXX\" we assume // that it used IoCreateSymbolicLink to create a // symbolic link \"\\DosDevices\\XXX\". Usually, there // is this understanding between related apps/drivers. // // An application might also peruse the DEVICEMAP // section of the registry, or use the QueryDosDevice // API to enumerate the existing symbolic links in the // system. // oh,my god,为什么一定要这个什么symbolic links呢,如果有的话,我也不用这么烦了? 还有没有更简单的方法呀? |
|
10楼#
发布于:2002-10-15 13:37
这好象是我曾经做过的一个类,专门用来动态安装/卸载驱动的。不过参考了Filemon和DDK中的相关源代码。
|
|
|
11楼#
发布于:2004-10-12 18:14
斑竹知道怎么在安全模式load驱动吗?
|
|
12楼#
发布于:2004-12-05 08:32
楼主,结果如何给大家总结一下那
|
|
13楼#
发布于:2004-12-05 09:02
这个是最终做出来的com组件,安装后就可以用里面的函数加载和卸载驱动了。我最终也是这么用,至于是抄谁的,我也不记得了 :D :D :D :P :P :P :P
|
|
|