Win 7为防火墙添加一条规则

来源:互联网 发布:flash cs6 mac 破解版 编辑:程序博客网 时间:2024/05/21 06:43

代码如下,直接执行shell

TCHAR szModulePath[MAX_PATH] = {0};GetModuleFileName(GetModuleHandle(NULL), szModulePath, sizeof(szModulePath) / sizeof(TCHAR));string strParameters = "firewall add allowedprogram ";strParameters += szModulePath;strParameters += " udpSrv2 enable";SHELLEXECUTEINFO shellExecute = {0};shellExecute.cbSize = sizeof SHELLEXECUTEINFO;shellExecute.fMask = SEE_MASK_NOCLOSEPROCESS;shellExecute.lpFile = "netsh";shellExecute.lpParameters = strParameters.c_str();shellExecute.nShow = SW_HIDE;if (ShellExecuteEx(&shellExecute)){WaitForSingleObject(shellExecute.hProcess, 2000);CloseHandle(shellExecute.hProcess);}

这样在程序启动时候防火墙就不会拦截。

原创粉丝点击