免安装WinPcap的方式建立应用程序或者安装程序
2007-10-10 22:41
591 查看
免安装WinPcap的方式建立应用程序或者安装程序
2007-05-17 19:01:20
大 中 小
前段时间使用WinPcap开发了一个捕获分析软件。还算顺利,但是在制作安装包的时候遇到一些问题。我当然不愿意让别人使用我的软件的时候安装两次,最好免安装绿色版,后来经过分析。发现一些规律,我使用Delphi7+WinPcap3.1可以实现绿色免安装使用。之前在网上看到很多都不太实用。在Xp和2000下测试成功。
下面介绍我是如何制作绿色版本的。
1)准备WinPcap的文件
首先在可以先安装WinPcap3.1(好像最新到了4.0了,不过3.1稳定),然后在
把%SystemRoot%System32目录下:
Packet.dll,wpcap.dll,WanPacket.dll,pthreadVC.dll
和%SystemRoot%System32/drivers目录下:
npf.sys
还有Winpcap安装目录下:
daemon_mgm.exe,NetMonInstaller.exe,npf_mgm.exe,rpcapd.exe
共9个文件复制到应用程序根目录。
2)在应用程序中编写代码
procedure TMonForm.FormCreate(Sender: TObject);
var
lpBuf:array[0..254] of Char;
ls_Driver : String;
ls_NpfFile:String;
ls_Lcname:String;
ls_windows:String;
begin
//获取%SystemRoot%的目录
GetWindowsDirectory(lpBuf,254);
ls_windows := StrPas(lpbuf);
//获取系统目录%SystemRoot%System32
GetSystemDirectory(lpBuf,254);
GS_SystemDir := StrPas(lpbuf);
//复制npf.sys到系统目录,并删除假目录,有时候会出现目录名和文件
//同名导致应用程序启动后看不到网卡
ls_Driver := GS_SystemDir + '/drivers';
ls_NpfFile := ls_Driver + '/npf.sys';
ls_Lcname := ExtractFilePath(Application.ExeName) + 'npf.sys';
RemoveDirectory(PChar(ls_NpfFile));
RemoveDirectory(PChar(GS_SystemDir + '/Packet.dll'));
RemoveDirectory(PChar(GS_SystemDir + '/WanPacket.dll'));
RemoveDirectory(PChar(GS_SystemDir + '/wpcap.dll'));
binPath := ExtractFilePath(Application.ExeName) ; //应用程序根目录
//判断是否存在该系统文件
if not FileExists(ls_Lcname) then
begin
Application.MessageBox(Pchar('丢失系统文件!'),
PChar('错误'), MB_OK + MB_ICONSTOP);
Application.Terminate;
end;
RemoveDirectory(PChar(ls_NpfFile));
CopyFile(PChar(ls_Lcname),PChar(ls_NpfFile),false);
CopyFile(PChar(ExtractFilePath(Application.ExeName)
+ 'Packet.dll'),PChar(GS_SystemDir + '/Packet.dll'),false);
CopyFile(PChar(ExtractFilePath(Application.ExeName)
+ 'WanPacket.dll'),PChar(GS_SystemDir + '/WanPacket.dll'),
false);
CopyFile(PChar(ExtractFilePath(Application.ExeName) + 'wpcap.dll'),
PChar(GS_SystemDir + '/wpcap.dll'),false);
CopyFile(PChar(ExtractFilePath(Application.ExeName)
+ 'pthreadVC.dll'),PChar(GS_SystemDir + '/pthreadVC.dll'),
false);
CopyFile(PChar(ls_Lcname),PChar(ls_NpfFile),false);
//这是关键部分--->启动捕获服务
WinExec(PChar(binPath + '/NetMonInstaller.exe u'),SW_HIDE);
WinExec(PChar(binPath + '/daemon_mgm.exe -u'),SW_HIDE);
WinExec(PChar(binPath + '/npf_mgm.exe -u'),SW_HIDE);
WinExec(PChar(binPath + '/npf_mgm.exe -r'),SW_HIDE);
WinExec(PChar(binPath + '/daemon_mgm.exe -r'),SW_HIDE);
WinExec(PChar(binPath + '/NetMonInstaller.exe i'),SW_HIDE);
//启动显示界面
//......下面就是应用程序代码,完全可以实现免安装和一体化打包
end;
相关文章推荐
- vs.net应用程序图标以及制作安装程序快捷方式图标设置
- vs.net应用程序图标以及制作安装程序快捷方式图标设置
- 解决Installer重新安装补丁错误-"无法打开此修补程序包。请确认该修补程序包存在,并且您可以访问它,或者与应用程序供应商联系,以确认这是否是一个有效的 Windows Installer 修补程序包。"
- 您的手机上未安装应用程序 android 点击快捷方式提示未安装程序的解决
- vs.net应用程序图标以及制作安装程序快捷方式图标设置
- Android 在安装完成界面,点击打开应用程序。在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开。(为了把问题写清楚,标题一定要长长长........)
- Android 在安装完成界面,点击打开应用程序。在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开。(为了把问题写清楚,标题一定要长长长........)
- Android 在安装完成界面,点击打开应用程序。在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开
- 腾讯 QQ for Linux 的安装及 tar.gz版本QQ 建立快捷方式
- Visual Studio .NET 无法创建或打开应用程序。问题很可能是因为本地Web服务器上没有安装所需的组件。请运行Visual Studio .NET安装程序并
- 手把手教你用C#打包应用程序(安装程序)【卸载模块已添加】
- 没有找到mingwm10.dll,因此这个程序未能启动。重新安装应用程序可能会修复此问题
- iOS 以无线方式安装企业级应用程序
- QT程序打包--教你做一个可安装的应用程序
- 程序提示安装失败,或者安装未成功处理
- 手把手教你用C#打包应用程序(安装程序)【卸载模块已添加】
- [VS2008] Debug版本程序发布后 由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题
- 【Android应用开发】-(18)静默方式实现批量安装卸载应用程序
- xp中 “控制面板”->“用户帐户”->“更改用户登录注销方式” 出现 一个最近安装的程序已停用欢迎界面和快速用户切换
- SQL Server补丁:“以前进行的程序安装创建了挂起的文件操作,应用程序需要重启”的错误