求COM组件-Hnetcfg.dll也就是NetSharingManager
google了,baidu了,没看到完整的编程资料,就连msdn在线也没有找到,有使用过的兄弟提示一下,3Q

解决方案 »

  1.   

     /// <summary>
            /// 获取防火墙管理的当前策略
            /// </summary>
            /// <returns>返回策略对应的 object</returns>
            public static object FirewallCurrentProfile()
            {
                //获取管理防火墙的COM组件的type
                Type fwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", true);
                //创建一个COM组件的实例
                object fwMgr = Activator.CreateInstance(fwMgrType);
                //获取实例的LocalPolicy属性
                object localPolicy = fwMgrType.InvokeMember("LocalPolicy", BindingFlags.GetProperty, null, fwMgr, null);            return localPolicy;
                //获取 LocalPolicy属性的子属性CurrentProfile
                return localPolicy.GetType().InvokeMember("CurrentProfile", BindingFlags.GetProperty, null, localPolicy, null);
            }        /// <summary>
            /// 设置系统自带防火墙的可用状态
            /// </summary>
            /// <param name="Enabled">true为开启,false为关闭</param>
            public static void SetFirewallEnableStatus(bool enabled)
            {
                //设置CurrentProfile的FirewallEnabled 属性值,来开启或关闭防火墙
                object profile = FirewallCurrentProfile();
                profile.GetType().InvokeMember("FirewallEnabled", BindingFlags.SetProperty, null, profile, new object[] { enabled });
            }        public static void SetFirewallExceptionStatus(bool allowed)
            {
                object profile = FirewallCurrentProfile();
                profile.GetType().InvokeMember("ExceptionsNotAllowed", BindingFlags.SetProperty, null, profile, new object[] { allowed });
            }