Add to Windows XP Firewall

Here's a quick program i wrote the other day, you can use it as you wish. It will simple add your program to the WinXP firewall exception list.

http://www.rohitab.com/discuss/topic/13561-add-to-windows-xp-firewall/ 

#include <stdio.h>
#include <windows.h>

int AddToWindowsFirewall(char *displayname,char * exepath);

int main()
{
 char dspname[MAX_PATH] = "";
 char exepath[MAX_PATH] = "";

 printf("Add To WinXP SP2 Firewall Exeception List\nBy Smith\n\n");

 printf("Enter display name: ");
 gets(dspname);

 printf("Enter exe path: ");
 gets(exepath);

 if(AddToWindowsFirewall(dspname,exepath))
 {
  printf("Success!\n");
 }else{
  printf("Failure!\n");
 }
 return 0;
}

int AddToWindowsFirewall(char *displayname,char * exepath)
{
 HKEY hKey;
 
 char filedata[MAX_PATH] = "";

 wsprintf(filedata,"%s:*:Enabled:%s",exepath,displayname);

 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"System\\ControlSet001\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List",0,KEY_ALL_ACCESS,&hKey)) return 0;
 if(RegSetValueEx(hKey,exepath,0,REG_SZ,(unsigned char*)filedata,sizeof(filedata))) return 0;
 
 RegCloseKey(hKey);

 return 1;//Success
}

posted on 2011-03-08 23:19 挑灯看剑 阅读(292) 评论(0)  编辑 收藏 引用 所属分类: C/C++

只有注册用户登录后才能发表评论。
<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

公告

【自我介绍】 08年南开大学硕士毕业 最近关注:算法、Linux、c++、高并发 爱好:滑旱冰、打乒乓球、台球、保龄球

常用链接

随笔分类(139)

文章分类

我常去的网站

技术博客(都是大牛)

技术站点

搜索

积分与排名