关闭防火墙

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

int WFDisable( );

int main()
{
 int wf;

 wf = WFDisable( );
 if( wf == 0 ) {
  printf( "wf< success\n" );
 }
 else {
  printf( "wf< error: %i\n", wf );
 }
 getchar();

 return 0;
}

int WFDisable()
{
 SERVICE_STATUS sStatus;
 
 SC_HANDLE hManager = OpenSCManager( NULL, NULL, 0xF003F );
 if( hManager == NULL ) {
  return( 1 );
 }
 //win7下防火墙服务名为MpsSvc
    //xp下防火墙服务名为SharedAccess
 SC_HANDLE hService = OpenService( hManager, (const char*)"MpsSvc", 0xF01FF );
 if( hService == NULL ) {
  return( 2 );
 }
 BOOL bControl = ControlService( hService, 0x00000001, &sStatus );
 if( bControl == 0 ) {
  return( 3 );
 }
 CloseServiceHandle( hManager );
 CloseServiceHandle( hService );

 return( 0 );
}

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

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

导航

公告

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

常用链接

随笔分类(139)

文章分类

我常去的网站

技术博客(都是大牛)

技术站点

搜索

积分与排名