NDIS中间层驱动自动安装WinDDK 自带例子Passthru driver的自动安装.docx_第1页
NDIS中间层驱动自动安装WinDDK 自带例子Passthru driver的自动安装.docx_第2页
NDIS中间层驱动自动安装WinDDK 自带例子Passthru driver的自动安装.docx_第3页
NDIS中间层驱动自动安装WinDDK 自带例子Passthru driver的自动安装.docx_第4页
NDIS中间层驱动自动安装WinDDK 自带例子Passthru driver的自动安装.docx_第5页
免费预览已结束,剩余2页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

从上一个叫做Preinstall的例子copy过来的,然后修改了一点,WinDDK 自带的bindview可以作为参考,他也是从那里copy的,呵呵DWORD GetServiceInfFilePath_Passthru( LPTSTR lpFilename, DWORD nSize)/ Get Path to This ModuleDWORD nResult;TCHAR szDrive _MAX_DRIVE ;TCHAR szDir _MAX_DIR ;nResult = GetModuleFileName( NULL, lpFilename, nSize );if( nResult = 0 )return 0;_tsplitpath( lpFilename, szDrive, szDir, NULL, NULL );_tmakepath( lpFilename, szDrive, szDir, _T (netsf), _T(.inf) );return (DWORD )_tcslen( lpFilename );DWORD GetServiceInfFilePath_PassthruMP( LPTSTR lpFilename, DWORD nSize)/ Get Path to This ModuleDWORD nResult;TCHAR szDrive _MAX_DRIVE ;TCHAR szDir _MAX_DIR ;nResult = GetModuleFileName( NULL, lpFilename, nSize );if( nResult = 0 )return 0;_tsplitpath( lpFilename, szDrive, szDir, NULL, NULL );_tmakepath( lpFilename, szDrive, szDir, _T (netsf_m), _T(.inf) );return (DWORD )_tcslen( lpFilename );DWORD InstallDriver_Passthru()DWORD nResult;/_tprintf( _T(Installing %s.n), NDISPROT_FRIENDLY_NAME );nResult = MessageBox(NULL, _T(你要安装Passthru 网络驱动? ), _T (Passthru网络过滤驱动), MB_OKCANCEL | MB_ICONINFORMATION );if( nResult != IDOK )return 0;/ Get Path to Service INF File/ -/ The INF file is assumed to be in the /same folder as this application.TCHAR szFileFullPath _MAX_PATH ;/第一次在一个系统上使用这个程序安装Passthru时,会出现安装失败的情况,或者/安装成功,但passthru miniport的部分没有安装上去,/在windows 目录下的setupapi.log文件中可以看到/安装失败记录,错误是找不到文件。在“设备管理器”选择显示隐藏设备后/也不会在网络适配器下面看到passthru miniport项。/但手动安装在本地网络属性-安装-”服务“选择/硬盘上netsf.inf进行安装成功候,再用程序安装就可以了。/在网络上查了一下,这个问题应该是因为Passthru这个驱动需要两个inf文件,/而netsf_m.inf并不没有被复制到/系统的inf 目录(c:windowsinf)去。/虽然netsf.inf 里面有CopyInf = netsf_m.inf项要求复制netsf_m.inf/但这个不能正常工作(The CopyINF directive, by design, /is only observed if the original INF is /not yet in the INF directory. So to work around the problem, /you have to /update your installation app (snetcfg) to also copy the Net /class (miniport) /inf using SetupCopyOEMInf when it comes to installing IM drivers. Make sure /you specify a fully qualified path of the INF in the SetupCopyOEMInf /arguments. /)/所以这个问题的解决就是自己把netsf_m.inf这个文件放到c:windowsinf目录去。/这可以通过在netsf.inf里面添加/copyfile项,像copy Passthru.sys一样添加一项copy netsf_m.inf的项。/另一种方法就是像下面这样添加调用/SetupCopyOEMInfW来复制netsf_m.inf的代码TCHAR szDrive _MAX_DRIVE ;TCHAR szDir _MAX_DIR ;TCHAR szDirWithDrive_MAX_DRIVE+_MAX_DIR;nResult = GetServiceInfFilePath_PassthruMP( szFileFullPath, MAX_PATH );if( nResult = 0 )/_tprintf( _T(Unable to get INF file path.n) );MessageBox(NULL, _T(获取INF文件路径失败!),_T(安装程序错误提示),MB_OK);return 0;/ Get the path where the INF file is./_tsplitpath( szFileFullPath, szDrive, szDir, NULL, NULL );_tcscpy( szDirWithDrive, szDrive );_tcscat( szDirWithDrive, szDir );if ( !SetupCopyOEMInfW(szFileFullPath,szDirWithDrive, / Other files are in the/ same dir. as primary INFSPOST_PATH, / First param is path to INF0, / Default copy styleNULL, / Name of the INF after/ its copied to %windir%inf0, / Max buf. size for the aboveNULL, / Required size if non-nullNULL) / Optionally get the filename/ part of Inf name after it is copied.)MessageBox(NULL, _T(复制PasstruMP 的inf安装文件到系统目录失败!),_T(安装程序错误提示),MB_OK);nResult = GetServiceInfFilePath_Passthru( szFileFullPath, MAX_PATH );if( nResult = 0 )/ _tprintf( _T(Unable to get INF file path.n) );MessageBox(NULL, _T(获取INF文件路径失败!),_T(安装程序错误提示),MB_OK);return 0;/_tprintf( _T(INF Path: %sn), szFileFullPath );HRESULT hr=S_OK;/_tprintf( _T(PnpID: %sn), _T( ms_passthru);hr = InstallSpecifiedComponent(szFileFullPath, /驱动安装的inf文件路径, 适当修改吧_T (ms_passthru), /NDISPROT_SERVICE_PNP_DEVICE_ID, /这个也要适当修改的&GUID_DEVCLASS_NETSERVICE /NDIS Protocal 类型);if( hr != S_OK )/*ErrMsg( hr, LInstallSpecifiedComponentn );*/MessageBox(NULL, _T(安装驱动失败!),_T(安装程序错误提示),MB_OK);elseMessageBox(NULL, _T(成功安装驱动!),_T(安装程序提示),MB_OK);return 0;DWORD UninstallDriver_Passthru()/_tprintf( _T(Uninstalling %s.n), NDISPROT_FRIENDLY_NAME );int nResult = MessageBox(NULL, _T(你要卸载Passthru网络驱动? ), _T (Passthru网络过滤驱动), MB_OKCANCEL | MB_ICONINFORMATION );if( nResult != IDOK )return 0;INetCfg *pnc;INetCfgComponent *pncc;INetCfgClass *pncClass;INetCfgClassSetup *pncClassSetup;LPTSTR lpszApp;GUID guidClass;OBO_TOKEN obo;HRESULT hr;hr = HrGetINetCfg( TRUE, APP_NAME, &pnc, &lpszApp );if ( hr = S_OK ) / Get a reference to the network component to uninstall./hr = pnc-FindComponent( _T (ms_passthru), &pncc );if ( hr = S_OK )/ Get the class GUID./hr = pncc-GetClassGuid( &guidClass );if ( hr = S_OK )/ Get a reference to components class./hr = pnc-QueryNetCfgClass( &guidClass,IID_INetCfgClass,(PVOID *)&pncClass );if ( hr = S_OK )/ Get the setup interface./hr = pncClass-QueryInterface( IID_INetCfgClassSetup,(LPVOID *)&pncClassSetup );if ( hr = S_OK )/ Uninstall the component./ZeroMemory( &obo,sizeof(OBO_TOKEN) );obo.Type = OBO_USER;hr = pncClassSetup-DeInstall( pncc,&obo,NULL );if ( (hr = S_OK) | (hr = NETCFG_S_REBOOT) )hr = pnc-Apply();if ( (hr != S_OK) & (hr != NETCFG_S_REBOOT) )/ErrMsg( hr,/ LCouldnt apply the changes after/ L uninstalling %s.,/ _T (ms_passthru );MessageBox(NULL, _T (卸载驱动之后无法成功应用!),_T (安装程序错误提示),MB_OK);elseMessageBox(NULL, _T(成功卸载驱动!),_T(安装程序提示),MB_OK);else/ErrMsg( hr,/ LFailed to uninstall %s.,/ _T(ms_passthru );MessageBox(NULL, _T(卸载网络组件失败!),_T(安装程序错误提示),MB_OK);ReleaseRef( pncClassSetup );else/ErrMsg( hr,/LCouldnt get an interface to setup class. );MessageBox(NULL, _T(无法得到安装类接口!),_T(安装程序错误提示),MB_OK);ReleaseRef( pncClass );else/ErrMsg( hr,/ LCouldnt get a pointer to class interface / Lof %s.,/ _T (ms_passthru) );MessageBox(NULL, _T(无法得到安装类接口!),_T(安装程序错误提示),MB_OK);else/ErrMsg( hr,/ LCoul

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论