![]() |
Sylloge
A C# helper library
|
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 using System; 00017 using System.Collections; 00018 using System.Collections.Generic; 00019 using System.Data; 00020 using System.Diagnostics; 00021 using System.Text; 00022 using System.Runtime.InteropServices; 00023 00024 namespace Sylloge.Device 00025 { 00029 public static class Manager 00030 { 00034 public enum DeviceState 00035 { 00039 Enable, 00043 Disable 00044 } 00045 00046 #region Class Methods and Properties 00047 00054 public static bool SetDeviceState(string match, DeviceState deviceState) 00055 { 00056 // TODO: why is this commented out??? fix this!!! 00057 00058 00059 00060 return false; 00061 //try { 00062 // System.Guid CurrentGuid = System.Guid.Empty; 00063 // IntPtr h = Sylloge.Win32.SetupDiGetClassDevs(ref CurrentGuid, 00064 // IntPtr.Zero, 00065 // IntPtr.Zero, 00066 // Sylloge.Win32.Constants.DIGCF_ALLCLASSES | Sylloge.Win32.Constants.DIGCF_PRESENT); 00067 // if (h == Sylloge.Win32.Constants.INVALID_HANDLE_VALUE) { return false; } 00068 // Win32.SP_DEVINFO_DATA DeviceInfoData = new Win32.SP_DEVINFO_DATA(); 00069 00070 // Win32.SP_DEVICE_INTERFACE_DATA dia = new Win32.SP_DEVICE_INTERFACE_DATA(); 00071 // dia.cbSize = Marshal.SizeOf(dia); 00072 // // start the enumeration 00073 // bool success = Win32.SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref DEVCLASS_NET, i++, ref dia); 00074 00075 00076 // DeviceInfoData.cbSize = 28; 00077 // // Devices exist for class 00078 // DeviceInfoData.devInst = 0; 00079 // DeviceInfoData.classGuid = System.Guid.Empty; 00080 // DeviceInfoData.reserved = IntPtr.Zero; 00081 // int Index = 0; 00082 // StringBuilder DeviceName = new StringBuilder(""); 00083 // int Timeout = 0; 00084 // DeviceName.Capacity = Win32.Constants.MAX_DEV_LEN; 00085 // while (Sylloge.Win32.SetupDiEnumDeviceInfo(DeviceInfo, Index, DeviceInfoData)) { 00086 // while (!Sylloge.Win32.SetupDiGetDeviceRegistryProperty(DeviceInfo, ref DeviceInfoData, Win32.Constants.SPDRP_DEVICEDESC, 0, DeviceName, Win32.Constants.MAX_DEV_LEN, IntPtr.Zero)) { 00087 // Sylloge.Win32.SetupDiGetDeviceRegistryProperty(DeviceInfo, ref DeviceInfoData, Win32.Constants.SPDRP_DEVICEDESC, IntPtr.Zero, 00088 // if (Timeout++ > 20) { break; } // Skip 00089 // } 00090 // if (DeviceName.ToString().ToLower().Contains(match.ToLower())) { 00091 // Sylloge.DeviceManager.ChangeDeviceState(DeviceInfo, DeviceInfoData, deviceState); 00092 // break; // Once we find and disable/enable then bail 00093 // } 00094 // Index++; 00095 // } 00096 // Win32.SetupDiDestroyDeviceInfoList(DeviceInfo); 00097 //} catch (Exception ex) { 00098 // Console.WriteLine(ex.Message); 00099 // return false; 00100 //} 00101 //return true; 00102 } 00103 00111 private static bool ChangeDeviceState(IntPtr deviceInfo, Sylloge.WinAPI.SP_DEVINFO_DATA did, DeviceState deviceState) 00112 { 00113 return false; 00114 //try { 00115 // // Marshalling vars 00116 // int ChangeParametersSize = 0; 00117 // IntPtr ChangeParametersPointer = default(IntPtr); 00118 // int DeviceInfoDataSize = 0; 00119 // IntPtr DeviceInfoDataPointer = default(IntPtr); 00120 // Win32.DevicePropertyChangeParameters Value = new Win32.DevicePropertyChangeParameters(); 00121 // if (deviceState == DeviceState.Enable) { 00122 // Value.ClassInstallHeader.cbSize = Marshal.SizeOf(Value.ClassInstallHeader); 00123 // Value.ClassInstallHeader.InstallFunction = Win32.Constants.DIF_PROPERTYCHANGE; 00124 // Value.StateChange = Win32.Constants.DICS_ENABLE; 00125 // Value.Scope = Win32.Constants.DICS_FLAG_GLOBAL; 00126 // Value.HwProfile = 0; 00127 // // Marshal the params 00128 // ChangeParametersSize = Marshal.SizeOf(Value); 00129 // ChangeParametersPointer = Marshal.AllocHGlobal(ChangeParametersSize); 00130 // Marshal.StructureToPtr(Value, ChangeParametersPointer, true); 00131 // DeviceInfoDataSize = Marshal.SizeOf(did); 00132 // DeviceInfoDataPointer = Marshal.AllocHGlobal(DeviceInfoDataSize); 00133 // if ((Win32.SetupDiSetClassInstallParams(deviceInfo, DeviceInfoDataPointer, ChangeParametersPointer, Marshal.SizeOf(Value)))) { 00134 // Win32.SetupDiCallClassInstaller(Win32.Constants.DIF_PROPERTYCHANGE, deviceInfo, DeviceInfoDataPointer); 00135 // } 00136 // Value.ClassInstallHeader.cbSize = Marshal.SizeOf(Value.ClassInstallHeader); 00137 // Value.ClassInstallHeader.InstallFunction = Win32.Constants.DIF_PROPERTYCHANGE; 00138 // Value.StateChange = Win32.Constants.DICS_ENABLE; 00139 // Value.Scope = Win32.Constants.DICS_FLAG_CONFIGSPECIFIC; 00140 // Value.HwProfile = 0; 00141 // } else { 00142 // Value.ClassInstallHeader.cbSize = Marshal.SizeOf(Value.ClassInstallHeader); 00143 // Value.ClassInstallHeader.InstallFunction = Win32.Constants.DIF_PROPERTYCHANGE; 00144 // Value.StateChange = Win32.Constants.DICS_DISABLE; 00145 // Value.Scope = Win32.Constants.DICS_FLAG_CONFIGSPECIFIC; 00146 // Value.HwProfile = 0; 00147 // } 00148 // //Marshal the params 00149 // ChangeParametersSize = Marshal.SizeOf(Value); 00150 // ChangeParametersPointer = Marshal.AllocHGlobal(ChangeParametersSize); 00151 // Marshal.StructureToPtr(Value, ChangeParametersPointer, true); 00152 // DeviceInfoDataSize = Marshal.SizeOf(did); 00153 // DeviceInfoDataPointer = Marshal.AllocHGlobal(DeviceInfoDataSize); 00154 // Marshal.StructureToPtr(did, DeviceInfoDataPointer, true); 00155 // bool SetupDiClassParamsResult = Win32.SetupDiSetClassInstallParams(deviceInfo, DeviceInfoDataPointer, ChangeParametersPointer, Marshal.SizeOf(Value)); 00156 // bool SetupDiClassInstallerResult = Win32.SetupDiCallClassInstaller(Win32.Constants.DIF_PROPERTYCHANGE, deviceInfo, DeviceInfoDataPointer); 00157 // if ((!SetupDiClassParamsResult || !SetupDiClassInstallerResult)) { 00158 // // Sylloge.G.Out("Unable to change device state"); 00159 // Console.WriteLine("Unable to change device state"); 00160 // return false; 00161 // } 00162 //} catch (Exception ex) { 00163 // //Sylloge.G.Out("Unable to change device state", ex); 00164 // Console.WriteLine(ex.Message); 00165 // return false; 00166 //} 00167 //return true; 00168 } 00169 00170 #endregion 00171 } 00172 00173 }
1.7.4