启用禁止使用USB接口,启用禁止使用外网

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

跟着上次的小工具启用禁止使用外网,也不是如何高技术含量的,拿来用就行了,所以那里就不多表明,代码里有简短介绍

叁个小工具,功用有启用禁用外网、USB接口,可由劳务端socket长链接实行操控客户端从而达到完毕前面包车型地铁这么些功用,那里贴上着力代码,先给上启用禁止使用USB接口吧,那些点子可每一日启用禁止使用,从前用过三个改usb接口状态格外格局非常的小行,对于早已插进去的没啥功用了,这几个是新兴改过的

1个小工具,功用有启用禁止使用外网、USB接口,可由劳动端socket长链接举行操控客户端从而达到完结前边的那么些效应,那里贴上着力代码,先给上启用禁止使用USB接口吧,这几个办法可随时启用禁止使用,以前用过1个改usb接口状态相当方式非常小行,对于早已插进去的没啥功效了,这几个是后来改过的

启用禁止使用外网方法

启用禁止使用外网方法

启用USB

启用USB

美高梅开户网址 1美高梅开户网址 2

美高梅开户网址 3美高梅开户网址 4

美高梅开户网址 5美高梅开户网址 6

美高梅开户网址 7美高梅开户网址 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

启用禁止使用USB接口,启用禁止使用外网。View Code

View Code

View Code

互联网设置的一个Helper

网络设置的一个Helper

 禁用USB

 禁用USB

美高梅开户网址 9美高梅开户网址 10

美高梅开户网址 11美高梅开户网址 12

美高梅开户网址 13美高梅开户网址 14

美高梅开户网址 15美高梅开户网址 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便是10分存款和储蓄的

判定获得操作系统位数

判断获得操作系统位数

(上多少个是启用禁止使用USB)

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

美高梅开户网址 17美高梅开户网址 18

美高梅开户网址 19美高梅开户网址 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

操作注册表

操作注册表

美高梅开户网址 21美高梅开户网址 22

美高梅开户网址 23美高梅开户网址 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用了

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

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

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图