黑客风云——风云网络
设为首页 加入收藏 我要投稿 网站地图

您现在的位置: 黑客风云 >> 黑客文章 >> 黑客进阶 >> 黑客编程 >> 正文
·完美空间提供500M免费AS04-10·企业安全之YY内网准入以04-09
·企业安全之意识与策略04-09·剑走偏锋:IIS漏洞利用04-09
·我来免费网提供100M免费04-09·1122mb.com提供20G超大免04-08
·映像劫持与反劫持技术04-07·让所有"暴力删除工具"无04-07
·入侵88red系统的详细过程04-07·Sql Injection脚本注入终04-07
·vbs+delphi 反弹后门生成04-07·飞讯网提供100MB免费PHP04-07
·突破SQL注入攻击时输入框04-04·结合内核和病毒技术的最04-04
·Real Player rmoc3260.d04-04·亿万网络今月最后为您提04-04
·php+mysql 5 sql inject04-03·Real Player rmoc3260.d04-03
·oblog文件下载漏洞04-03·免费啦提供1G-2G免费全能04-03
·完全解析网页后门和挂马04-02·一句话开3389(只测试过04-02
·萧萧免费空间网提供100M04-02·谷道免费空间网提供1G免04-01
·从本地入手解决双线路由03-31·sablog 1.6 多个跨站漏洞03-31
·富文本编辑器的跨站脚本03-31·Cookie注入是怎样产生的03-31
[推荐]如何透过程序来控制 Windows (XP) 防火墙的开关
      ★★★★★

如何透过程序来控制 Windows (XP) 防火墙的开关

文章整理发布:黑客风云 文章来源:www.05112.com 更新时间:2007-8-20 9:08:56

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;

文章录入:cainiaowang    责任编辑:cainiaowang 
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
VIP 专 区
Copyright @2006 黑客风云 ●业务联系:QQ 联系怪人 联系奇人 Email:给怪人发邮件 给奇人发邮件
ICP备案:冀06009886