示例#1
0
        public static void ChangeDeviceEnabledState(
            DeviceInfoListHandle deviceInfoList, ref SP_DEVINFO_DATA deviceInfoData,
            DiClassInstallState state, DiClassInstallScope scope,
            DiClassInstallFunction installFunction
            )
        {
            var pcp = new SP_PROPCHANGE_PARAMS();

            pcp.Header.cbSize          = (uint)Marshal.SizeOf(pcp.Header.GetType());
            pcp.Header.InstallFunction = installFunction;
            pcp.StateChange            = state;
            pcp.Scope     = scope;
            pcp.HwProfile = 0;

            SetupDiSetClassInstallParams(deviceInfoList, ref deviceInfoData, pcp);

            if (!SetupDiCallClassInstaller(
                    installFunction, deviceInfoList.DangerousGetHandle(), ref deviceInfoData
                    ))
            {
                var error = Marshal.GetLastWin32Error();
                if (error != 0)
                {
                    throw new Win32Exception(error);
                }
                else
                {
                    throw new Exception("Failed to change device enabled state");
                }
            }
        }
示例#2
0
 public static extern bool SetupDiCallClassInstaller(
     DiClassInstallFunction installFunction,
     IntPtr deviceInfoSet,
     ref SP_DEVINFO_DATA deviceInfoData
     );