Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            HH_Lib lib   = new HH_Lib();
            string nicId = null;

            lib.GetAll().ForEach(it =>
            {
                Console.WriteLine("Processing Device");
                Console.Write(it.friendlyName);
                Console.Write("---");
                Console.Write(it.hardwareId);
                Console.WriteLine("\n");
                if (it.friendlyName.Contains("82578"))
                {
                    nicId = it.hardwareId;
                }
            });
            if (nicId == null)
            {
                Console.WriteLine("\n\nNIC not found");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("\n\nNIC found, ID is " + nicId);
                Console.WriteLine("Disabling NIC");
                lib.SetDeviceState(new String[] { nicId }, false);
                System.Threading.Thread.Sleep(5000);
                Console.WriteLine("Re-enabling NIC");
                lib.SetDeviceState(new String[] { nicId }, true);
                Console.WriteLine("Done");
                System.Threading.Thread.Sleep(1000);
            }
        }
Ejemplo n.º 2
0
        private static void ResetGPU(DEVICE_INFO device)
        {
            DeviceStatus current = GetStatus(device);

            if (current == DeviceStatus.Enabled)
            {
                hhlib.SetDeviceState(device, false);
                if (!cliOnly)
                {
                    PrintStatus(device);
                }
            }
            else if (current == DeviceStatus.Disabled)
            {
                if (!cliOnly)
                {
                    Console.WriteLine("Device currently disabled.\nWill attempt to enable...");
                }
            }
            else if (current == DeviceStatus.Unknown)
            {
                if (!cliOnly)
                {
                    Console.WriteLine("Device currently in unknown state.\nWill attempt to enable...");
                }
            }
            Thread.Sleep(1000);
            hhlib.SetDeviceState(device, true);
            PrintStatus(device);
            if (!cliOnly && GetStatus(device) == DeviceStatus.Enabled)
            {
                Console.WriteLine($"{device.name} Successfully reset.");
                Thread.Sleep(3000);
            }
            else if (!cliOnly && GetStatus(device) == DeviceStatus.Disabled)
            {
                Console.WriteLine($"{device.name} not successfully reenabled / reset (look above for more info).");
                Thread.Sleep(3000);
            }
            else if (!cliOnly && GetStatus(device) == DeviceStatus.Unknown)
            {
                Console.WriteLine($"{device.name} is in an unknown state. There seems to be an issue.");
                Thread.Sleep(3000);
            }
            else
            {
                Console.WriteLine(1);
            }
        }
Ejemplo n.º 3
0
        //Name:     button1_Clck
        //Inputs:   object, eventArgs
        //Outputs:  none
        //Remarks:  We are using this button to demonstrate enabling a
        //          hardware device.  There are several things worth
        //          noting.  First, just to be safe we are disabling
        //          hardware notifcations until we are done.  The UI
        //          thread in .NET won't let the WndProc method run
        //          to my knowledge while you are in here but if you
        //          were invoking these methods on different callers it
        //          would be worthwhile to disable the notifications
        //          during.  The call to SetDeviceState is designed
        //          to allow you to pass in multiple devices in an
        //          array to disable, even though we are currently just
        //          doing the selected one.  Also the search is a
        //          substring search so be careful not to use something
        //          so generic that it will affect more devices than
        //          the one(s) you intended.  See the notes for the
        //          SetDeviceState method in the library for some
        //          important info.
        private void button1_Click(object sender, EventArgs e)
        {
            if (listdevices.SelectedIndices.Count == 0)
            {
                return;
            }

            hwh.CutLooseHardwareNotifications(this.Handle);
            try
            {
                hwh.SetDeviceState(HardwareList[listdevices.SelectedIndices[0]], true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }
            hwh.HookHardwareNotifications(this.Handle, true);
        }
Ejemplo n.º 4
0
        //Name:     button1_Clck
        //Inputs:   object, eventArgs
        //Outputs:  none
        //Remarks:  We are using this button to demonstrate enabling a
        //          hardware device.  There are several things worth
        //          noting.  First, just to be safe we are disabling
        //          hardware notifcations until we are done.  The UI
        //          thread in .NET won't let the WndProc method run
        //          to my knowledge while you are in here but if you
        //          were invoking these methods on different callers it
        //          would be worthwhile to disable the notifications
        //          during.  The call to SetDeviceState is designed
        //          to allow you to pass in multiple devices in an
        //          array to disable, even though we are currently just
        //          doing the selected one.  Also the search is a
        //          substring search so be careful not to use something
        //          so generic that it will affect more devices than
        //          the one(s) you intended.  See the notes for the
        //          SetDeviceState method in the library for some
        //          important info.
        private void button1_Click(object sender, EventArgs e)
        {
            if (listdevices.SelectedIndices.Count == 0)
            {
                return;
            }

            //Enable
            string[] devices = new string[1];
            hwh.CutLooseHardwareNotifications(this.Handle);
            var hardwareId = HardwareList[listdevices.SelectedIndices[0]].hardwareId;

            if (string.IsNullOrEmpty(hardwareId))
            {
                return;
            }
            devices[0] = hardwareId;
            hwh.SetDeviceState(devices, true);
            hwh.HookHardwareNotifications(this.Handle, true);
        }
Ejemplo n.º 5
0
 //This is a workaround since vJoy does not support disabling all 4 joysticks.
 public static void DisablevJoyDLL()
 {
     try
     {
         HardwareHelperLib.HH_Lib lb = new HH_Lib();
         lb.SetDeviceState("vJoy Device", false);
     }
     catch
     {
         Log(null, new Logging.LogEventArgs("Error: Unable to disable vJoy."));
     }
 }
Ejemplo n.º 6
0
 public static void EnablevJoyDLL()
 {
     try
     {
         HardwareHelperLib.HH_Lib lb = new HH_Lib();
         lb.SetDeviceState("vJoy Device", true);
     }
     catch
     {
         Log(null, new Logging.LogEventArgs("Error: Unable to complete vJoy enable."));
     }
 }
Ejemplo n.º 7
0
        public void SetDisableDevice(bool resume)
        {
            string[] devices = new string[1];

            if (resume == false)
            {
                hwh.CutLooseHardwareNotifications(this.Handle);
                devices[0] = comboBox1.SelectedItem.ToString();
                hwh.SetDeviceState(devices, false);
                hwh.HookHardwareNotifications(this.Handle, true);

                tempo           = 6;
                timerDD.Enabled = true;
            }

            if (resume == true)
            {
                hwh.CutLooseHardwareNotifications(this.Handle);
                devices[0] = comboBox1.SelectedItem.ToString();
                hwh.SetDeviceState(devices, true);
                hwh.HookHardwareNotifications(this.Handle, true);
            }
        }
Ejemplo n.º 8
0
        public void DeviceToggle(string ApplyWay)
        {
            /*
             * ApplyWay(적용방식) 앞숫자 : USB 뒷숫자 : CAM   | 0 : 허용  1: 차단
             * 값: 11 (USB,CAM 허용) | 값: 10 (USB만 허용) | 값 : 01 (CAM만 허용) | 값 : 00 (모두 허용)
             */
            if (this.ApplyWay != ApplyWay)
            {
                if (ApplyWay == "11")
                {
                    usbBlockApply = false;
                    camBlockApply = false;
                }
                else if (ApplyWay == "10")
                {
                    usbBlockApply = false;
                    camBlockApply = true;
                }
                else if (ApplyWay == "01")
                {
                    usbBlockApply = true;
                    camBlockApply = false;
                }
                else if (ApplyWay == "00")
                {
                    usbBlockApply = true;
                    camBlockApply = true;
                }
                this.ApplyWay = ApplyWay;

                HardwareList = hwh.GetAll();

                string usbRegLocation = "SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices";
                string camRegLocation = "SYSTEM\\ControlSet001\\Services\\usbvideo";

                RegistryKey usbRegKey = Registry.LocalMachine.OpenSubKey(usbRegLocation, true);
                usbRegKey = Registry.LocalMachine.CreateSubKey(usbRegLocation);
                RegistryKey camRegKey = Registry.LocalMachine.OpenSubKey(camRegLocation, true);

                if (camRegKey == null)
                {
                    camRegKey = Registry.LocalMachine.CreateSubKey(camRegLocation);
                }

                if (usbBlockApply == true)
                {
                    usbRegKey.SetValue("Deny_All", 1, RegistryValueKind.DWord); //레지 값 추가
                }
                else
                {
                    string RegCheckValue = Convert.ToString(usbRegKey.GetValue("Deny_All"));
                    if (RegCheckValue == "1")
                    {
                        usbRegKey.DeleteValue("Deny_All");
                    }
                }

                if (camBlockApply == true)
                {
                    camRegKey.SetValue("Start", 4, RegistryValueKind.DWord); //레지 값 추가
                }
                else
                {
                    camRegKey.SetValue("Start", 3, RegistryValueKind.DWord); //레지 값 추가
                }
                int UsbVideoIndexNumber = 0;
                //string TempStr = "";
                foreach (var device in HardwareList)
                {
                    if (camBlockApply == true || camBlockApply == false)
                    {
                        if (device.service == "usbvideo")
                        {
                            hwh.SetDeviceState(HardwareList[UsbVideoIndexNumber], false);
                            hwh.SetDeviceState(HardwareList[UsbVideoIndexNumber], true);
                            break;
                        }
                        UsbVideoIndexNumber++;
                    }
                }

                /* 현호화 회의하에 일단 보류
                 * TempStr = device.hardwareId;
                 * if (TempStr != "")
                 * {
                 * if (TempStr.Substring(0, 7) == "USBSTOR")
                 * {
                 *   MessageBox.Show(UsbVideoIndexNumber.ToString());
                 *   hwh.SetDeviceState(HardwareList[UsbVideoIndexNumber], false);
                 *   hwh.SetDeviceState(HardwareList[UsbVideoIndexNumber], true);
                 *   break;
                 * }
                 * }*/
            }
        }
Ejemplo n.º 9
0
        public void SetDeviceEnable(string devname, bool devbool)
        {
            HH_Lib hwh = new HH_Lib();

            hwh.SetDeviceState(new string[] { devname, null }, devbool);
        }
Ejemplo n.º 10
0
 private void DisableAudioDevice()
 {
     hwh.SetDeviceState(audioDevice, false);
 }