| 网站首页 | 资讯 | Hack | 漏洞 | 网管 | 编程 | 培训 | 品黑页 | 软件 | 论坛 | 动画 | 视频 | 经典 | 教学站 | 黑客点睛 | 
服务导航 我要发布 主力频道 空间域名 精华收集 服务器出租 黑客培训 光盘刻录 特色服务 解决方案 我要投诉
您现在的位置: 华夏黑客同盟 >> 编程 >> 其它编程 >> 正文 用户登录 新用户注册
透过程序控制XP防火墙开关           ★★★ 【字体:
透过程序控制XP防火墙开关
作者:不详 文章来源:华盟收集 点击数: 更新时间:2007-9-4

Dim objFW As Object   

    Set objFW = CreateObject("HNetCfg.FwMgr").LocalPolicy.CurrentProfile
    With objFW
        .FirewallEnabled = True ' True 开启 , False 关闭
             .ExceptionsNotAllowed = True ' [ 不允许例外 ] 选项 , True 勾 , 反之则不勾
    End With


procedure Set_WindowsXP_FireWall(Enable: boolean);
// 需引用 winsvc, shellapi
// Set_WindowsXP_FireWall(false); // 关闭Windows Xp 防火牆
//
var
  SCM, hService: LongWord;
  sStatus: TServiceStatus;
begin
  if Enable = false then
  begin
    SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
    hService := OpenService(SCM, PChar('SharedAccess'), SERVICE_ALL_ACCESS);
    ControlService(hService, SERVICE_CONTROL_STOP, sStatus);
    CloseServiceHandle(hService);
  end;
end;

设定Port 的部份,不过还没测试!不过我还是希望写成简单形式的函数库呼叫方式,大家一起來测试吧!

出处:http://www-new.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22122056.html
Example of both adding and removing a tcp port from the globaly open ports list (in Windows XP firewall)

Regards,
Russell

// Include ActiveX and ComObj in uses clause (also Variants for D6 and up)

const
  NET_FW_PROFILE_DOMAIN      =  0;
  NET_FW_PROFILE_STANDARD    =  1;

const
  NET_FW_IP_PROTOCOL_TCP     = 6;
  NET_FW_IP_PROTOCOL_UDP     = 17;

const
  NET_FW_SCOPE_ALL           =  0;

const
  NET_FW_IP_VERSION_ANY      =  2;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var  ovMgr:         OleVariant;
     ovProfile:     OleVariant;
     ovPort:        OleVariant;
begin

  // Create manager interface
  ovMgr:=CreateOleObject('HNetCfg.FwMgr');

  // Resource protection
  try
     // Get local profile interface
     ovProfile:=ovMgr.LocalPolicy.CurrentProfile;
     // Resource protection
     try
        // Create new port interface
        ovPort:=CreateOleObject('HNetCfg.FwOpenPort');
        try
           // Set port properties
           ovPort.Port:=81;
           ovPort.Name:='Whatever';
           ovPort.Scope:=NET_FW_SCOPE_ALL;
           ovPort.IpVersion:=NET_FW_IP_VERSION_ANY;
           ovPort.Protocol:=NET_FW_IP_PROTOCOL_TCP;
           ovPort.Enabled:=True;
           // Resource protection
           try
              // Add to globally open ports
              ovProfile.GloballyOpenPorts.Add(ovPort);

              ////
              // .... do whatever ....
              ////

           finally
              // Remove from globally open ports
              ovProfile.GloballyOpenPorts.Remove(81, NET_FW_IP_PROTOCOL_TCP);
           end;
        finally
           // Release interface
           ovPort:=Unassigned;
        end;
     finally
        // Release interface
        ovProfile:=Unassigned;
     end;
  finally
     // Release interface
     ovMgr:=Unassigned;
  end;

end;

责任编辑:朱倩  联系方式  Email:朱倩
电话:51228163
  • 上一篇编程:

  • 下一篇编程:
  • (只显示最新5条。评论内容只代表网友观点,与本站立场无关!)
    姓 名:
    * 游客填写  ·注册用户
    主 页:
    评 分:
    1分 2分 3分 4分 5分
    评论内容:
    验证码: *
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  • 最新hack更新
    最新推荐资讯
    相关编程
    xp下双开3389源码
    xp下双开3389源码
    xp下双开3389源码
    让程序通过XP防火墙
    防火墙的分类及优缺点综述
    浮点数计算精度控制
    XP核心驱动漏洞代码
    让你的程序过xp防火墙
    开启和关闭xp 防火墙
    用VB制作远程控制软件
    最新会员软件
    最新推荐视频
    最新推荐动画

    Copyright @ 2005 77169.Net Inc. All rights reserved. 华夏黑客同盟 版权所有
    北京市电信通提供网络带宽

    mailto:webmaster@77169.net
    咨询QQ号:836982 / 59280880
    联系站长 QQ38588913
    热线电话: 86-10-67634029/676229433
    京ICP证041431号