随之上次的小工具启用禁止使用外网,也不是怎样高技术含量的,拿来用就行了,所以这边就不多表明,代码里有简短介绍

启用禁止使用外网,启用禁止使用USB接口。紧接着上次的小工具启用禁止使用外网,也不是什么样高技术含量的,拿来用就行了,所以那里就不多表达,代码里有简要介绍

二个小工具,作用有启用禁止使用外网、USB接口,可由服务端socket长链接实行操控客户端从而达到达成前面的这一个功用,那里贴上着力代码,先给上启用禁止使用USB接口吧,那个办法可随时启用禁止使用,在此之前用过三个改usb接口状态非凡格局十分小行,对于已经插进去的没啥功用了,这些是后来改过的

叁个小工具,功效有启用禁止使用外网、USB接口,可由劳动端socket长链接进行操控客户端从而达到实现前面包车型的士这个效应,那里贴上着力代码,先给上启用禁止使用USB接口吧,那一个方法可随时启用禁用,在此之前用过三个改usb接口状态不行格局一点都不大行,对于早已插进去的没啥功能了,那么些是后来改过的

启用禁止使用外网方法

启用禁止使用外网方法

启用USB

启用USB

金沙注册送58 1金沙注册送58 2

金沙注册送58 3金沙注册送58 4

金沙注册送58 5金沙注册送58 6

金沙注册送58 7金沙注册送58 8

        public bool ForbiddenNetWork(bool isForbidden)
        {
            try
            {
                //禁用dns
                if (isForbidden)
                {
                    //如果双网卡:114.114.114.114|115.115.115.115|116.116.116.116 8.8.8.8
                    List<string[]> getDNSList = NetWorkSettingHelper.GetDNS();
                    if (getDNSList.Count <= 0)
                    {
                        VertifyPwd.isWlan = !setConfig.isForbiddenNetWork;
                        ErrorCollectHelper.InfoLog("禁用DNS", "获取DNS为空,不做任何设置");
                        return false;
                    }
                    //禁用dns
                    List<string[]> newgateways = new List<string[]>();
                    for (int j = 0; j < getDNSList.Count; j++)
                    {
                        //strDns网卡:114.114.114.114|115.115.115.115|116.116.116.116
                        string[] strDns = getDNSList[j];
                        //禁用dns
                        string[] forbiddenDns = new string[strDns.Length];
                        for (int i = 0; i < strDns.Length; i++)
                        {
                            //dns:1.1.1.1
                            forbiddenDns[i] = string.Format("{0}.{0}.{0}.{0}", i + 1);
                        }
                        //需要设置禁用的dns为1.1.1.1,默认不处理
                        if (string.Equals(string.Join("|", strDns), string.Join("|", forbiddenDns), StringComparison.OrdinalIgnoreCase))
                        {
                            VertifyPwd.isWlan = !setConfig.isForbiddenNetWork;
                            ErrorCollectHelper.InfoLog("禁用DNS", "DNS为1.1.1.1等默认值,不做任何设置");
                            return false;
                        }
                        else//保存dns状态,可能多网卡,目前最多考虑双网卡
                        {
                            if (j == 0)
                            {
                                setConfig.dns0 = string.Join("|", strDns);
                            }
                            else if (j == 1)
                            {
                                setConfig.dns1 = string.Join("|", strDns);
                            }
                        }
                        //禁用dns
                        newgateways.Add(forbiddenDns);
                    }
                    NetWorkSettingHelper.SetDNS(newgateways);
                    //保存dns
                    setConfig.isForbiddenNetWork = true;
                    VertifyPwd.isWlan = false;
                    setConfig.Save();
                }
                else//启用dns
                {
                    //默认最多考虑双网卡
                    List<string[]> getDNSList = new List<string[]>();
                    if (!string.IsNullOrEmpty(setConfig.dns0))
                    {
                        getDNSList.Add(setConfig.dns0.Split('|'));
                    }
                    if (!string.IsNullOrEmpty(setConfig.dns1))
                    {
                        getDNSList.Add(setConfig.dns1.Split('|'));
                    }
                    if (getDNSList.Count > 0)
                    {
                        NetWorkSettingHelper.SetDNS(getDNSList);
                        setConfig.isForbiddenNetWork = false;
                        VertifyPwd.isWlan = true;
                        setConfig.Save();
                        return true;
                    }
                    else
                    {
                        VertifyPwd.isWlan = !setConfig.isForbiddenNetWork;
                        ErrorCollectHelper.InfoLog("启用DNS", "没有找到保存的DNS,无法启用");
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("设置网络访问错误", ex.ToString());
                return false;
            }
        }
        public bool ForbiddenNetWork(bool isForbidden)
        {
            try
            {
                //禁用dns
                if (isForbidden)
                {
                    //如果双网卡:114.114.114.114|115.115.115.115|116.116.116.116 8.8.8.8
                    List<string[]> getDNSList = NetWorkSettingHelper.GetDNS();
                    if (getDNSList.Count <= 0)
                    {
                        VertifyPwd.isWlan = !setConfig.isForbiddenNetWork;
                        ErrorCollectHelper.InfoLog("禁用DNS", "获取DNS为空,不做任何设置");
                        return false;
                    }
                    //禁用dns
                    List<string[]> newgateways = new List<string[]>();
                    for (int j = 0; j < getDNSList.Count; j++)
                    {
                        //strDns网卡:114.114.114.114|115.115.115.115|116.116.116.116
                        string[] strDns = getDNSList[j];
                        //禁用dns
                        string[] forbiddenDns = new string[strDns.Length];
                        for (int i = 0; i < strDns.Length; i++)
                        {
                            //dns:1.1.1.1
                            forbiddenDns[i] = string.Format("{0}.{0}.{0}.{0}", i + 1);
                        }
                        //需要设置禁用的dns为1.1.1.1,默认不处理
                        if (string.Equals(string.Join("|", strDns), string.Join("|", forbiddenDns), StringComparison.OrdinalIgnoreCase))
                        {
                            VertifyPwd.isWlan = !setConfig.isForbiddenNetWork;
                            ErrorCollectHelper.InfoLog("禁用DNS", "DNS为1.1.1.1等默认值,不做任何设置");
                            return false;
                        }
                        else//保存dns状态,可能多网卡,目前最多考虑双网卡
                        {
                            if (j == 0)
                            {
                                setConfig.dns0 = string.Join("|", strDns);
                            }
                            else if (j == 1)
                            {
                                setConfig.dns1 = string.Join("|", strDns);
                            }
                        }
                        //禁用dns
                        newgateways.Add(forbiddenDns);
                    }
                    NetWorkSettingHelper.SetDNS(newgateways);
                    //保存dns
                    setConfig.isForbiddenNetWork = true;
                    VertifyPwd.isWlan = false;
                    setConfig.Save();
                }
                else//启用dns
                {
                    //默认最多考虑双网卡
                    List<string[]> getDNSList = new List<string[]>();
                    if (!string.IsNullOrEmpty(setConfig.dns0))
                    {
                        getDNSList.Add(setConfig.dns0.Split('|'));
                    }
                    if (!string.IsNullOrEmpty(setConfig.dns1))
                    {
                        getDNSList.Add(setConfig.dns1.Split('|'));
                    }
                    if (getDNSList.Count > 0)
                    {
                        NetWorkSettingHelper.SetDNS(getDNSList);
                        setConfig.isForbiddenNetWork = false;
                        VertifyPwd.isWlan = true;
                        setConfig.Save();
                        return true;
                    }
                    else
                    {
                        VertifyPwd.isWlan = !setConfig.isForbiddenNetWork;
                        ErrorCollectHelper.InfoLog("启用DNS", "没有找到保存的DNS,无法启用");
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("设置网络访问错误", ex.ToString());
                return false;
            }
        }
        public bool EnableUSB()
        {
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows", "RemovableStorageDevices", "");
            }
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
            }
            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "0", "REG_DWORD");
            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "0", "REG_DWORD");
            bool blDevices = SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "0", "REG_DWORD");


            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\", "USBSTOR", "");
            }
            bool blUsbStor = SetRegistValue("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR", "Start", "3", "REG_DWORD");

            if (GetSystemIs64() == "64")
            {

                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\", "RemovableStorageDevices", "");
                }
                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
                }
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "0", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "0", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "0", "REG_DWORD");
            }
            return blDevices && blUsbStor;
        }
        public bool EnableUSB()
        {
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows", "RemovableStorageDevices", "");
            }
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
            }
            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "0", "REG_DWORD");
            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "0", "REG_DWORD");
            bool blDevices = SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "0", "REG_DWORD");


            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\", "USBSTOR", "");
            }
            bool blUsbStor = SetRegistValue("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR", "Start", "3", "REG_DWORD");

            if (GetSystemIs64() == "64")
            {

                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\", "RemovableStorageDevices", "");
                }
                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
                }
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "0", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "0", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "0", "REG_DWORD");
            }
            return blDevices && blUsbStor;
        }

View Code

View Code

View Code

View Code

网络设置的一个Helper

网络设置的一个Helper

 禁用USB

 禁用USB

金沙注册送58 9金沙注册送58 10

金沙注册送58 11金沙注册送58 12

金沙注册送58 13金沙注册送58 14

金沙注册送58 15金沙注册送58 16

    public class NetWorkSettingHelper
    {


        public static void SetDNS(List<string[]> getways)
        {
            try
            {
                ManagementClass wmi = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = wmi.GetInstances();
                ManagementBaseObject inPar = null;
                ManagementBaseObject outPar = null;
                int n = 0;

                foreach (ManagementObject mo in moc)
                {
                    //如果没有启用IP设置的网络设备则跳过
                    if (!(bool)mo["IPEnabled"])
                        continue;

                    //设置网关地址
                    if (getways.Count > 0)
                    {
                        //如果dns为空,则if判断永远为false,因此注释
                        //if (mo["DNSServerSearchOrder"] != null && (mo["DNSServerSearchOrder"] as String[])[0] != null)
                        //{
                            inPar = mo.GetMethodParameters("SetDNSServerSearchOrder");
                            inPar["DNSServerSearchOrder"] = getways[n++];
                            outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null);
                       // }
                    }
                    mo.Clone();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }



        public static List<string[]> GetDNS()
        {
            try
            {
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection nics = mc.GetInstances();
                List<string[]> getways = new List<string[]>();
                foreach (ManagementObject nic in nics)
                {
                    if (Convert.ToBoolean(nic["ipEnabled"]))
                    {
                        if (nic["DNSServerSearchOrder"] != null && (nic["DNSServerSearchOrder"] as String[])[0] != null)
                        {
                            getways.Add(nic["DNSServerSearchOrder"] as String[]);
                        }
                        nic.Clone();
                    }
                }
                return getways;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
    public class NetWorkSettingHelper
    {


        public static void SetDNS(List<string[]> getways)
        {
            try
            {
                ManagementClass wmi = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = wmi.GetInstances();
                ManagementBaseObject inPar = null;
                ManagementBaseObject outPar = null;
                int n = 0;

                foreach (ManagementObject mo in moc)
                {
                    //如果没有启用IP设置的网络设备则跳过
                    if (!(bool)mo["IPEnabled"])
                        continue;

                    //设置网关地址
                    if (getways.Count > 0)
                    {
                        //如果dns为空,则if判断永远为false,因此注释
                        //if (mo["DNSServerSearchOrder"] != null && (mo["DNSServerSearchOrder"] as String[])[0] != null)
                        //{
                            inPar = mo.GetMethodParameters("SetDNSServerSearchOrder");
                            inPar["DNSServerSearchOrder"] = getways[n++];
                            outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null);
                       // }
                    }
                    mo.Clone();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }



        public static List<string[]> GetDNS()
        {
            try
            {
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection nics = mc.GetInstances();
                List<string[]> getways = new List<string[]>();
                foreach (ManagementObject nic in nics)
                {
                    if (Convert.ToBoolean(nic["ipEnabled"]))
                    {
                        if (nic["DNSServerSearchOrder"] != null && (nic["DNSServerSearchOrder"] as String[])[0] != null)
                        {
                            getways.Add(nic["DNSServerSearchOrder"] as String[]);
                        }
                        nic.Clone();
                    }
                }
                return getways;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
        public bool DisableUSB()
        {
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows", "RemovableStorageDevices", "");
            }
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
            }

            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "1", "REG_DWORD");
            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "1", "REG_DWORD");
            bool blDevices = SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "1", "REG_DWORD");


            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\", "USBSTOR", "");
            }
            bool blUsbStor = SetRegistValue("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR", "Start", "4", "REG_DWORD");


            if (GetSystemIs64() == "64")
            {

                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\", "RemovableStorageDevices", "");
                }
                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
                }

                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "1", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "1", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "1", "REG_DWORD");
            }
            return blDevices && blUsbStor;
        }
        public bool DisableUSB()
        {
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows", "RemovableStorageDevices", "");
            }
            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
            }

            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "1", "REG_DWORD");
            SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "1", "REG_DWORD");
            bool blDevices = SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "1", "REG_DWORD");


            if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR"))
            {
                CreateRegistKey("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\", "USBSTOR", "");
            }
            bool blUsbStor = SetRegistValue("HKEY_LOCAL_MACHINE", @"SYSTEM\CurrentControlSet\services\USBSTOR", "Start", "4", "REG_DWORD");


            if (GetSystemIs64() == "64")
            {

                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\", "RemovableStorageDevices", "");
                }
                if (!IsExistRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"))
                {
                    CreateRegistKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\", "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "");
                }

                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Read", "1", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_Write", "1", "REG_DWORD");
                SetRegistValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", "Deny_All", "1", "REG_DWORD");
            }
            return blDevices && blUsbStor;
        }

View Code

View Code

View Code

View Code

早先暗许dns存在配置文件里,setConfig正是那多少个存款和储蓄的

伊始暗中认可dns存在配置文件里,setConfig就是非凡存款和储蓄的

判断获得操作系统位数

认清得到操作系统位数

(上1个是启用禁止使用USB)

(上2个是启用禁止使用USB)

金沙注册送58 17金沙注册送58 18

金沙注册送58 19金沙注册送58 20

        private string GetSystemIs64()
        {
            try
            {
                string systemtype = "";
                ObjectQuery oq = new ObjectQuery("select AddressWidth from Win32_Processor");
                ManagementObjectSearcher query1 = new ManagementObjectSearcher(oq);
                ManagementObjectCollection moc = query1.Get();
                foreach (ManagementObject mo in moc)
                {
                    try
                    {
                        systemtype = mo["addressWidth"].ToString();
                    }
                    catch
                    {
                        systemtype += "null";
                        continue;
                    }
                }
                moc = null;
                oq = null;
                query1 = null;
                return systemtype;

            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("获取操作系统位数错误", ex.ToString());
                return "";
            }
        }
        private string GetSystemIs64()
        {
            try
            {
                string systemtype = "";
                ObjectQuery oq = new ObjectQuery("select AddressWidth from Win32_Processor");
                ManagementObjectSearcher query1 = new ManagementObjectSearcher(oq);
                ManagementObjectCollection moc = query1.Get();
                foreach (ManagementObject mo in moc)
                {
                    try
                    {
                        systemtype = mo["addressWidth"].ToString();
                    }
                    catch
                    {
                        systemtype += "null";
                        continue;
                    }
                }
                moc = null;
                oq = null;
                query1 = null;
                return systemtype;

            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("获取操作系统位数错误", ex.ToString());
                return "";
            }
        }

View Code

View Code

操作注册表

操作注册表

金沙注册送58 21金沙注册送58 22

金沙注册送58 23金沙注册送58 24

        private bool IsExistRegistKey(string rootKey, string subKey)
        {
            bool isExistKey = false;
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey subkey = hkml.OpenSubKey(subKey, true);
                    if (subkey != null)
                        isExistKey = true;
                }
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("打开注册表错误", ex.ToString());
            }
            return isExistKey;
        }
        private void CreateRegistKey(string rootKey, string subKey, string keyName, string keyValue)
        {
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey subkey = hkml.CreateSubKey(subKey);
                    if (subkey != null && keyName != "")
                        subkey.SetValue(keyName, keyValue, RegistryValueKind.String);
                }
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("创建注册表错误", ex.ToString());
            }
        }

        private bool SetRegistValue(string rootKey, string subKey, string key, string value, string type)
        {
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey secKey = hkml.OpenSubKey(subKey, true);
                    if (secKey != null)
                        secKey.SetValue(key, value, GetValueKind(type));
                    else
                    {
                        secKey = hkml.CreateSubKey(subKey);
                        if (secKey != null)
                            secKey.SetValue(key, value, GetValueKind(type));
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("修改注册表错误", ex.ToString());
                return false;
            }
        }
        private bool DeleteRegistValue(string rootKey, string subKey, string key)
        {
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey secKey = hkml.OpenSubKey(subKey, true);
                    if (secKey != null)
                    {
                        if (secKey.GetValue(key) != null)
                            secKey.DeleteValue(key);
                    }
                }
                return true;
            }
            catch (System.Exception ex)
            {
                ErrorCollectHelper.ErrorLog("删除注册表错误", ex.ToString());
                return false;
            }
        }
        private RegistryValueKind GetValueKind(string typeInfo)
        {
            switch (typeInfo)
            {
                case "REG_DWORD":
                    return RegistryValueKind.DWord;
                case "REG_SZ":
                    return RegistryValueKind.String;
                default:
                    return RegistryValueKind.None;
            }
        }
        private RegistryKey GetRegistryKey(string rootkey)
        {
            if (string.IsNullOrEmpty(rootkey))
                return null;
            switch (rootkey)
            {
                case "HKEY_CURRENT_USER":
                    return Registry.CurrentUser;
                case "HKEY_LOCAL_MACHINE":
                    return Registry.LocalMachine;
                case "HKEY_CLASSES_ROOT":
                    return Registry.ClassesRoot;
                case "HKEY_USERS":
                    return Registry.Users;
                case "HKEY_CURRENT_CONFIG":
                    return Registry.CurrentConfig;
                default:
                    return null;
            }
        }
        private bool IsExistRegistKey(string rootKey, string subKey)
        {
            bool isExistKey = false;
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey subkey = hkml.OpenSubKey(subKey, true);
                    if (subkey != null)
                        isExistKey = true;
                }
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("打开注册表错误", ex.ToString());
            }
            return isExistKey;
        }
        private void CreateRegistKey(string rootKey, string subKey, string keyName, string keyValue)
        {
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey subkey = hkml.CreateSubKey(subKey);
                    if (subkey != null && keyName != "")
                        subkey.SetValue(keyName, keyValue, RegistryValueKind.String);
                }
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("创建注册表错误", ex.ToString());
            }
        }

        private bool SetRegistValue(string rootKey, string subKey, string key, string value, string type)
        {
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey secKey = hkml.OpenSubKey(subKey, true);
                    if (secKey != null)
                        secKey.SetValue(key, value, GetValueKind(type));
                    else
                    {
                        secKey = hkml.CreateSubKey(subKey);
                        if (secKey != null)
                            secKey.SetValue(key, value, GetValueKind(type));
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                ErrorCollectHelper.ErrorLog("修改注册表错误", ex.ToString());
                return false;
            }
        }
        private bool DeleteRegistValue(string rootKey, string subKey, string key)
        {
            try
            {
                RegistryKey hkml = GetRegistryKey(rootKey);
                if (hkml != null)
                {
                    RegistryKey secKey = hkml.OpenSubKey(subKey, true);
                    if (secKey != null)
                    {
                        if (secKey.GetValue(key) != null)
                            secKey.DeleteValue(key);
                    }
                }
                return true;
            }
            catch (System.Exception ex)
            {
                ErrorCollectHelper.ErrorLog("删除注册表错误", ex.ToString());
                return false;
            }
        }
        private RegistryValueKind GetValueKind(string typeInfo)
        {
            switch (typeInfo)
            {
                case "REG_DWORD":
                    return RegistryValueKind.DWord;
                case "REG_SZ":
                    return RegistryValueKind.String;
                default:
                    return RegistryValueKind.None;
            }
        }
        private RegistryKey GetRegistryKey(string rootkey)
        {
            if (string.IsNullOrEmpty(rootkey))
                return null;
            switch (rootkey)
            {
                case "HKEY_CURRENT_USER":
                    return Registry.CurrentUser;
                case "HKEY_LOCAL_MACHINE":
                    return Registry.LocalMachine;
                case "HKEY_CLASSES_ROOT":
                    return Registry.ClassesRoot;
                case "HKEY_USERS":
                    return Registry.Users;
                case "HKEY_CURRENT_CONFIG":
                    return Registry.CurrentConfig;
                default:
                    return null;
            }
        }

View Code

View Code

上述内容都以比较固定死的,没什么技术含量,那些情节能够直接拿着作为helper用了

如上内容都以相比固化死的,没什么技术含量,这几个内容可以间接拿着作为helper用了

(下三个是启用禁止使用外网金沙注册送58 ,)

(下多个是启用禁止使用外网)

相关文章

网站地图xml地图