VC代码添加防火墙规则
来源:互联网 发布:9wifi九维网络登录 编辑:程序博客网 时间:2024/06/08 18:51
BOOL DealExecCmd(CString strCommandLine){USES_CONVERSION;STARTUPINFO StartInfo;memset(&StartInfo, '\0', sizeof(StartInfo));StartInfo.cb = sizeof(StartInfo); //name structureStartInfo.dwFlags = STARTF_USESHOWWINDOW;StartInfo.wShowWindow = SW_HIDE; //隐藏DOC窗口PROCESS_INFORMATION ProcInfo; //name structurememset(&ProcInfo, 0, sizeof(ProcInfo));bool flag = ::CreateProcess(NULL, strCommandLine.GetBuffer(), NULL, NULL, NULL, NULL, NULL, NULL, &StartInfo, &ProcInfo);strCommandLine.ReleaseBuffer();if(flag){WaitForSingleObject(ProcInfo.hProcess,INFINITE);//此方法主要是等待进程处理CloseHandle(ProcInfo.hThread);CloseHandle(ProcInfo.hProcess);}return flag;}BOOL AddFSystemFireWallRuler(CString strfileName, CString strName ){CString fireWallRuler;if( OSVersion::IsOSAtLeast( OSVersion::OSVersionEnum::WIN_VISTA ) ){fireWallRuler.Format(_T("netsh advfirewall firewall delete rule name=\"%s\" dir=in program=\"%s\""),strName, strfileName);DealExecCmd( fireWallRuler);fireWallRuler.Format(_T("netsh advfirewall firewall add rule name=\"%s\" dir=in program=\"%s\" action=allow"), strName, strfileName);DealExecCmd( fireWallRuler);}else{fireWallRuler.Format(_T("netsh firewall add allowedprogram \"%s\" %s ENABLE"), strfileName, strName);DealExecCmd( fireWallRuler);}return TRUE;}
开启防火墙:
netsh firewall set opmode mode=enable
关闭防火墙:
netsh firewall set opmode mode=disable
命令:netsh firewall
参数:
? // 显示命令列表
add // 添加防火墙配置
delete // 删除防火墙配置
dump // 显示一个配置脚本
help // 显示命令列表
reset // 将防火墙配置重置为默认值。
set // 设置防火墙配置
show // 显示防火墙配置
add allowedprogram // 添加防火墙允许的程序配置。
add portopening // 添加防火墙端口配置
delete allowedprogram // 删除防火墙允许的程序配置
delete portopening // 删除防火墙端口配置
set allowedprogram // 设置防火墙允许的程序配置
set icmpsetting // 设置防火墙 ICMP 配置
set logging // 设置防火墙记录配置
set multicastbroadcastrespon
set notifications // 设置防火墙通知配置
set opmode // 设置防火墙操作配置
set portopening // 设置防火墙端口配置
set service // 设置防火墙服务配置
show allowedprogram // 显示防火墙允许的程序配置
show config // 显示防火墙配置。
show currentprofile // 显示当前防火墙配置文件
show icmpsetting // 显示防火墙 ICMP 配置
show logging // 显示防火墙记录配置
show multicastbroadcastrespon
show notifications // 显示防火墙操作配置
show opmode // 显示防火墙端口配置
show portopening // 显示防火墙端口配置
show service // 显示防火墙服务配置
show state // 显示当前防火墙状态
例如:
命令:netsh firewall show allowedprogram //查看防火墙放行的程序
netsh firewall set portopening TCP 445 ENABLE //打开445端口
netsh firewall set portopening TCP 3389 ENABLE //
netsh firewall delete allowedprogram C:\A.exe //删除放行程序A.exe
netsh firewall set allowedprogram C:\A.exe A ENABLE //添加程序C盘下的A.exe并放行
netsh firewall add allowedprogram C:\A.exe A ENABLE //添加程序C盘下的A.exe并放行
- VC代码添加防火墙规则
- iptables防火墙添加规则
- NSIS 添加防火墙规则实战
- centos 防火墙添加删除规则
- Linux下如何添加防火墙规则
- Windows XPE为NetMeeting添加防火墙规则
- Win 7为防火墙添加一条规则
- CentOS 关闭SELINUX及添加防火墙规则
- dos 添加防火墙入站规则
- dos 添加防火墙入站规则
- 《批处理添加防火墙过滤危险端口规则》
- VC++添加服务代码
- Live Writer连接不上可以考虑添加防火墙规则
- 命令行添加防火墙规则及改变IIS站点的信息
- iptables防火墙规则的添加、删除、修改、保存
- Windows Server2008通过命令行方式添加防火墙规则
- iptables防火墙规则的添加、删除、修改、保存
- docker高级应用之智能添加与修改防火墙规则
- L1-018. 大笨钟
- java基础_day0002 循环_嵌套
- cordova插件生成工具类
- Matlab 在同一个坐标系下画颜色不相同的多个球体
- 基于驾驶行为数据的UBI车险模型(转)
- VC代码添加防火墙规则
- 已知指向节点p的指针,如何删除该节点(不知道链表头)
- Activity后台运行一段时间回来crash问题
- 急急急,求助:求会groovy语言的大神
- 算法提高 阮小二买彩票
- C 网页编辑器
- 独立显卡黑屏问题
- Android自定义View的实现方法,带你一步步深入了解View(四)
- <转>Spark执行模式解析