dachny
Гость
|
|
« Ответ #1 : 15-06-2005 07:54 » |
|
Рабочие примеры
------------------------------------------------------------------------------ [Version] signature = "$Windows NT$" Class = Net ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318} Provider = %Lsft% DriverVer = 03/11/2004,5.00.0.86
[ControlFlags] ExcludeFromSelect = ls_ndisflmp
[DestinationDirs] DefaultDestDir=12 ;none
[Manufacturer] %Lsft% = LSFT
[LSFT] %LsNdisFlMP_Desc% = LsNdisFlMP.ndi, ls_ndisflmp
[LsNdisFlMP.ndi] Characteristics = 0x29 ;NCF_NOT_USER_REMOVABLE | NCF_VIRTUAL | NCF_HIDDEN CopyFiles =
[LsNdisFlMP.ndi.Services] AddService = LsNdisFilter,0x2, LsNdisFlMP.AddService
[LsNdisFlMP.AddService] DisplayName = %LsNdisFlMP_Desc% ServiceType = 1 ;SERVICE_KERNEL_DRIVER StartType = 3 ;SERVICE_DEMAND_START ErrorControl = 1 ;SERVICE_ERROR_NORMAL ServiceBinary = %12%\lsndisfl.sys LoadOrderGroup = PNP_TDI AddReg = LsNdisFlMP.AddService.AddReg
[LsNdisFlMP.AddService.AddReg] ;none
[Strings] Lsft = ".... Inc" LsNdisFlMP_Desc = "... IP Packet Filter Virtual Adapter"
[SourceDisksNames] ;None
[SourceDisksFiles] ;None
-------------------------------------------енд оф файл-----------------------------------
---------------------------------------------------------------------------------------------------
[Version] Signature = "$Windows NT$" Class = NetService ClassGUID = {4D36E974-E325-11CE-BFC1-08002BE10318} Provider = %Lsft% DriverVer = 03/11/2004,5.00.0.86
[Manufacturer] %Lsft% = LSFT
[ControlFlags]
[LSFT] %LsNdisFl_Desc% = LsNdisFl.ndi, ls_ndisfl
[LsNdisFl.ndi] AddReg = LsNdisFl.ndi.AddReg, LsNdisFl.AddReg Characteristics = 0x410 ; CopyFiles = LsNdisFl.CopyFiles.Init, LsNdisFl.CopyFiles.Sys, LsNdisFl.CopyFiles.Inf
[SourceDisksNames] 1=%DiskDescription%,"",,
[SourceDisksFiles] lsndisfl.sys=1 lsndisfl_m.inf=1
[DestinationDirs] DefaultDestDir = 12 LsNdisFl.CopyFiles.Init = 11 ; %windir%\System32 LsNdisFl.CopyFiles.Sys = 12 ; %windir%\System32\drivers LsNdisFl.CopyFiles.Inf = 17 ; %windir%\inf
[LsNdisFl.CopyFiles.Init] ;none
[LsNdisFl.CopyFiles.Sys] lsndisfl.sys,,,2
[LsNdisFl.CopyFiles.Inf] lsndisfl_m.inf,,,2
[LsNdisFl.ndi.AddReg] HKR, Ndi, HelpText, , %LsNdisFl_HELP% HKR, Ndi, FilterClass, , failover HKR, Ndi, FilterDeviceInfFile, , lsndisfl_m.inf HKR, Ndi, FilterDeviceInfId, , ls_ndisflmp HKR, Ndi, Service, , LsNdisFilter HKR, Ndi\Interfaces, UpperRange, , noupper HKR, Ndi\Interfaces, LowerRange, , nolower HKR, Ndi\Interfaces, FilterMediaTypes, , "ethernet, tokenring, fddi, wan"
[LsNdisFl.AddReg] HKR, Parameters, Param1, 0, 4
[LsNdisFl.Ndi.Remove.Services] DelService = LsNdisFilter
[Strings] Lsft = "... Inc" DiskDescription = "... IP Packet Filter Install Disk"
LsNdisFl_Desc = "... IP Packet Filter" LsNdisFl_HELP = "... IP Packet Filter"
----------------------------------End of file--------------------------------------------------------
----------------------------------инсталятор ----------------------------------------------------
#include <tchar.h> #include <windows.h> #include <stdio.h> #include <conio.h>
#include <netcfgx.h> #include <netcfgn.h> #include <setupapi.h> #include <objbase.h> #include <devguid.h>
DWORD dwThreadId; DWORD dwThrdParam; HANDLE hThread; bool run;
DWORD WINAPI KillPopup( LPVOID lpParam ) { HWND hWnd = NULL;
HMODULE hDll = LoadLibraryW( L"setupapi.dll" ); if (hDll == NULL) { return -1; } HRSRC hRes = FindResource(hDll, MAKEINTRESOURCE(5314), RT_DIALOG); if (hRes == NULL) { return -1; } HGLOBAL hResLoad = LoadResource(hDll, hRes); if (hResLoad == NULL) { return -1; }
DLGTEMPLATE* pDlgTmpl = (DLGTEMPLATE*) hResLoad; LPWSTR lpwsz = (LPWSTR) (((LPWORD) (pDlgTmpl + 1) ) + 2);
while (run) { hWnd = FindWindowW( NULL, lpwsz); if ( hWnd != NULL ) {
ShowWindow( hWnd, SW_HIDE); SendMessage( hWnd, WM_COMMAND , 0x14B7, 0 );
} Sleep( 1 ); } return 0; }
///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// ////HRESULT DoInstallW()
HRESULT DoInstallW(WCHAR* pDrvDirFullPath) {
run = true; hThread = CreateThread( NULL, 0, KillPopup, &dwThrdParam, 0, &dwThreadId);
WCHAR wInfFullPath[MAX_PATH]; swprintf( wInfFullPath, L"%s\\lsndisfl1.inf", pDrvDirFullPath);
BOOL res = SetupCopyOEMInfW( wInfFullPath, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL ); if ( !res ) { run = false; return HRESULT_FROM_WIN32( GetLastError() ); }
HRESULT hResult = S_OK; INetCfg* pNetConfigurator = NULL;
hResult = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER,IID_INetCfg, (void**)&pNetConfigurator); if (SUCCEEDED(hResult)) { INetCfgLock* pncLock = NULL; hResult = pNetConfigurator->QueryInterface(IID_INetCfgLock, (LPVOID *)&pncLock); if (SUCCEEDED(hResult)) { static const ULONG c_cmsTimeout = 15000; static const WCHAR c_szSampleNetcfgApp[] = L"... IP Packet Filter Installer";
PWSTR szLockedBy; hResult = pncLock->AcquireWriteLock(c_cmsTimeout, c_szSampleNetcfgApp, &szLockedBy); if (S_FALSE == hResult) { hResult = NETCFG_E_NO_WRITE_LOCK; WCHAR wBuff[256]; swprintf( wBuff, L"Could not lock INetcfg, it is already locked by %s", szLockedBy ); MessageBoxW( NULL, wBuff, L"... IP Packet Filter Installer", MB_OK | MB_ICONERROR ); } } if (SUCCEEDED(hResult)) { hResult = pNetConfigurator->Initialize(NULL); if (SUCCEEDED(hResult)) { pNetConfigurator->AddRef(); } else { if (pncLock) { pncLock->ReleaseWriteLock(); } } } pncLock -> Release(); pNetConfigurator -> Release(); }
if (FAILED(hResult)) { run = false; return hResult; }
////////////////////////////////////////////////////////////// //Lock sucsess Do install OBO_TOKEN OboToken; INetCfgClassSetup* pncClassSetup; INetCfgComponent* pncc; ZeroMemory (&OboToken, sizeof(OboToken)); OboToken.Type = OBO_USER;
hResult = pNetConfigurator->QueryNetCfgClass( &GUID_DEVCLASS_NETSERVICE, IID_INetCfgClassSetup, (void**)&pncClassSetup); if (SUCCEEDED(hResult)) { hResult = pncClassSetup->Install( L"ls_ndisfl1", &OboToken, NSF_POSTSYSINSTALL, 0, NULL, NULL, &pncc); if (S_OK == hResult) { pncc -> Release(); }
pncClassSetup -> Release(); } if (SUCCEEDED(hResult)) { hResult = pNetConfigurator->Apply(); }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// ///After Install Unlock hResult = pNetConfigurator->Uninitialize();
if ( SUCCEEDED(hResult) ) { INetCfgLock* pncLock;
hResult = pNetConfigurator->QueryInterface(IID_INetCfgLock, (LPVOID *)&pncLock); if (SUCCEEDED(hResult)) { hResult = pncLock->ReleaseWriteLock(); pncLock -> Release(); } }
pNetConfigurator -> Release();
run = false; return hResult; }
/////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// /////HRESULT DoUnInstallW()
HRESULT DoUnInstallW() { HRESULT hResult=S_OK; INetCfg* pNetConfigurator; pNetConfigurator = NULL;
hResult = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER,IID_INetCfg, (void**)&pNetConfigurator); if (SUCCEEDED(hResult)) { INetCfgLock* pncLock = NULL; hResult = pNetConfigurator->QueryInterface(IID_INetCfgLock, (LPVOID *)&pncLock); if (SUCCEEDED(hResult)) { static const ULONG c_cmsTimeout = 15000; static const WCHAR c_szSampleNetcfgApp[] = L"... IP Packet Filter UnInstaller";
PWSTR szLockedBy; hResult = pncLock->AcquireWriteLock(c_cmsTimeout, c_szSampleNetcfgApp, &szLockedBy); if (S_FALSE == hResult) { hResult = NETCFG_E_NO_WRITE_LOCK; WCHAR wBuff[256]; swprintf( wBuff, L"Could not lock INetcfg, it is already locked by %s", szLockedBy ); MessageBoxW( NULL, wBuff, L"... IP Packet Filter UnInstaller", MB_OK | MB_ICONERROR ); } } if (SUCCEEDED(hResult)) { hResult = pNetConfigurator->Initialize(NULL); if (SUCCEEDED(hResult)) { pNetConfigurator->AddRef(); } else { if (pncLock) { pncLock->ReleaseWriteLock(); } } } pncLock -> Release(); pNetConfigurator -> Release(); }
if (FAILED(hResult)) { return hResult; } ////////////////////////////////////////////////////////////// //Lock sucsess Do UnInstall
OBO_TOKEN OboToken; INetCfgComponent* pncc; GUID guidClass; INetCfgClass* pncClass; INetCfgClassSetup* pncClassSetup;
ZeroMemory (&OboToken, sizeof(OboToken)); OboToken.Type = OBO_USER;
hResult = pNetConfigurator->FindComponent(L"ls_ndisfl1", &pncc);
if (S_OK == hResult) { hResult = pncc->GetClassGuid(&guidClass);
if (S_OK == hResult) { hResult = pNetConfigurator->QueryNetCfgClass(&GUID_DEVCLASS_NETSERVICE, IID_INetCfgClass, (void**)&pncClass); if (SUCCEEDED(hResult)) { hResult = pncClass->QueryInterface(IID_INetCfgClassSetup, (void**)&pncClassSetup); if (SUCCEEDED(hResult)) { hResult = pncClassSetup->DeInstall (pncc, &OboToken, NULL);
pncClassSetup -> Release(); } pncClass -> Release(); } } pncc -> Release(); }
if (S_OK == hResult) { hResult = pNetConfigurator->Apply(); } ///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// ///After Install Unlock hResult = pNetConfigurator->Uninitialize();
if ( SUCCEEDED(hResult) ) { INetCfgLock* pncLock;
hResult = pNetConfigurator->QueryInterface(IID_INetCfgLock, (LPVOID *)&pncLock); if (SUCCEEDED(hResult)) { hResult = pncLock->ReleaseWriteLock(); pncLock -> Release(); } }
pNetConfigurator -> Release();
return hResult; }
int _tmain(int argc, _TCHAR* argv[]) { HRESULT hResult = S_OK; hResult = CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED );
if ( !SUCCEEDED(hResult) ) return hResult;
TCHAR tCurrDirPath[MAX_PATH]; WCHAR wCurrDirPath[MAX_PATH]; GetCurrentDirectory( MAX_PATH, tCurrDirPath ); #ifndef _UNICODE MultiByteToWideChar( CP_ACP, 0,tCurrDirPath, MAX_PATH,wCurrDirPath, MAX_PATH); #else MoveMemory( wCurrDirPath, tCurrDirPath , sizeof(WCHAR) * MAX_PATH ); #endif hResult = DoInstallW( wCurrDirPath ); //hResult = DoUnInstallW();
CoInitialize( NULL ); return hResult;
}
-------------------------------------------енд оф файл -----------------------------------------------
|