Exemple #1
0
        public static bool ChildrenInstalled(string enumName)
        {
            UInt32 devStatus;
            UInt32 devProblemCode;

            SetupApi.SP_DEVINFO_DATA devInfoData =
                new SetupApi.SP_DEVINFO_DATA();
            devInfoData.cbSize = (uint)Marshal.SizeOf(devInfoData);

            using (SetupApi.DeviceInfoSet devInfoSet =
                       new SetupApi.DeviceInfoSet(
                       IntPtr.Zero,
                       enumName,
                       IntPtr.Zero,
                       SetupApi.DiGetClassFlags.DIGCF_PRESENT |
                       SetupApi.DiGetClassFlags.DIGCF_ALLCLASSES))
            {
                for (uint i = 0;
                     SetupApi.SetupDiEnumDeviceInfo(
                         devInfoSet.Get(),
                         i,
                         devInfoData);
                     ++i)
                {
                    CfgMgr32.CM_Get_DevNode_Status(
                        out devStatus,
                        out devProblemCode,
                        devInfoData.devInst,
                        0
                    );

                    if ((devStatus & (uint)SetupApi.DNFlags.DN_STARTED) == 0)
                    {
                        Trace.WriteLine(
                            enumName +
                            " child not started " +
                            devStatus.ToString()
                        );

                        return false;
                    }
                }
            }
            return true;
        }
Exemple #2
0
        private static void VifDisableEnable(bool enable)
        {
            string action = enable ? "enable" : "disable";

            Trace.WriteLine("===> VifDisableEnable: \'" + action + "\'");

            using (SetupApi.DeviceInfoSet devInfoSet =
                       new SetupApi.DeviceInfoSet(
                       IntPtr.Zero,
                       "XENVIF",
                       IntPtr.Zero,
                       SetupApi.DiGetClassFlags.DIGCF_PRESENT |
                       SetupApi.DiGetClassFlags.DIGCF_ALLCLASSES))
            {
                SetupApi.SP_DEVINFO_DATA devInfoData =
                    new SetupApi.SP_DEVINFO_DATA();

                devInfoData.cbSize = (uint)Marshal.SizeOf(devInfoData);

                for (uint i = 0;
                     SetupApi.SetupDiEnumDeviceInfo(
                         devInfoSet.Get(),
                         i,
                         devInfoData);
                     ++i)
                {
                    SetupApi.PropertyChangeParameters pcParams =
                        new SetupApi.PropertyChangeParameters();

                    pcParams.size = 8;
                    pcParams.diFunction = SetupApi.DI_FUNCTION.DIF_PROPERTYCHANGE;
                    pcParams.scope = SetupApi.Scopes.Global;

                    if (enable)
                    {
                        pcParams.stateChange = SetupApi.StateChangeAction.Enable;
                    }
                    else
                    {
                        pcParams.stateChange = SetupApi.StateChangeAction.Disable;
                    }

                    pcParams.hwProfile = 0;
                    var pinned = GCHandle.Alloc(pcParams, GCHandleType.Pinned);

                    byte[] temp = new byte[Marshal.SizeOf(pcParams)];
                    Marshal.Copy(
                        pinned.AddrOfPinnedObject(),
                        temp,
                        0,
                        Marshal.SizeOf(pcParams)
                    );

                    var pdd = GCHandle.Alloc(devInfoData, GCHandleType.Pinned);

                    if (!SetupApi.SetupDiSetClassInstallParams(
                            devInfoSet.Get(),
                            pdd.AddrOfPinnedObject(),
                            pinned.AddrOfPinnedObject(),
                            Marshal.SizeOf(pcParams)))
                    {
                        Win32Error.Set("SetupDiSetClassInstallParams");
                        Trace.WriteLine(Win32Error.GetFullErrMsg());
                    }

                    if (!SetupApi.SetupDiCallClassInstaller(
                            SetupApi.DI_FUNCTION.DIF_PROPERTYCHANGE,
                            devInfoSet.Get(),
                            pdd.AddrOfPinnedObject()))
                    {
                        Win32Error.Set("SetupDiCallClassInstaller");
                        Trace.WriteLine(Win32Error.GetFullErrMsg());
                    }

                    pdd.Free();
                    pinned.Free();
                }
            }
            Trace.WriteLine("<=== VifDisableEnable");
        }
Exemple #3
0
        private static void SetPVToolsVersionOnFirstRun(
            RegistryKey openRegKey)
        {
            string regValName = "PVToolsVersionOnFirstRun";
            int tmp = (int)openRegKey.GetValue(regValName, -1);
            string drvVer;

            if (tmp != -1)
            {
                // We can save some indentation..
                goto SetStaticVariable;
            }

            if (xenBusDev == (XenBus.Devs)0)
            {
                tmp = 0; // None
                drvVer = "0.0.0.0";
            }
            else
            {
                using (SetupApi.DeviceInfoSet devInfoSet =
                    new SetupApi.DeviceInfoSet(
                        IntPtr.Zero,
                        "PCI",
                        IntPtr.Zero,
                        SetupApi.DiGetClassFlags.DIGCF_ALLCLASSES |
                        SetupApi.DiGetClassFlags.DIGCF_PRESENT))
                {
                    int idx = Helpers.BitIdxFromFlag((uint)xenBusDev);

                    SetupApi.SP_DEVINFO_DATA devInfoData =
                        Device.FindInSystem(
                            XenBus.hwIDs[idx],
                            devInfoSet,
                            true
                        );

                    drvVer = Device.GetDriverVersion(
                        devInfoSet, devInfoData
                    );
                }

                // Split the DriverVersion string on the '.'
                // char and parse the 1st substring (major
                // version number)
                tmp = Int32.Parse(
                    drvVer.Split(new char[] { '.' })[0]
                );

                if (tmp != 8) // Eight
                {
                    tmp = 7; // LessThanEight
                }

            }

            Trace.WriteLine(
                "XenBus driver version on first run: \'" + drvVer + "\'"
            );

            openRegKey.SetValue(
                regValName,
                tmp,
                RegistryValueKind.DWord
            );

            SetStaticVariable:
            pvToolsVer = (PVToolsVersion)Enum.Parse(
                typeof(PVToolsVersion), tmp.ToString()
            );
        }
Exemple #4
0
        // Returns the device instance ID of the specified device
        // 'enum_device' should have the following format:
        // <enumerator>\<device_id>
        public static string GetDeviceInstanceId(string enum_device)
        {
            const int BUFFER_SIZE = 4096;
            string enumerator = enum_device.Split(new char[] { '\\' })[0];
            StringBuilder deviceInstanceId = new StringBuilder(BUFFER_SIZE);
            SetupApi.SP_DEVINFO_DATA devInfoData;
            int reqSize;

            using (SetupApi.DeviceInfoSet devInfoSet =
                new SetupApi.DeviceInfoSet(
                    IntPtr.Zero,
                    enumerator,
                    IntPtr.Zero,
                    SetupApi.DiGetClassFlags.DIGCF_ALLCLASSES |
                    SetupApi.DiGetClassFlags.DIGCF_PRESENT))
            {
                devInfoData = Device.FindInSystem(
                    enum_device,
                    devInfoSet,
                    false
                );

                if (devInfoData == null)
                {
                    return "";
                }

                if (!SetupApi.SetupDiGetDeviceInstanceId(
                        devInfoSet.Get(),
                        devInfoData,
                        deviceInstanceId,
                        BUFFER_SIZE,
                        out reqSize))
                {
                    Win32Error.Set("SetupDiGetDeviceInstanceId");
                    throw new Exception(Win32Error.GetFullErrMsg());
                }
            }

            return deviceInstanceId.ToString();
        }
        public static void UninstallDriversAndDevices()
        {
            using (SetupApi.DeviceInfoSet devInfoSet =
                        new SetupApi.DeviceInfoSet(
                        IntPtr.Zero,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        SetupApi.DiGetClassFlags.DIGCF_ALLCLASSES))
            {
                foreach (string hwId in pvHwIds)
                {
                    Helpers.UninstallDriverPackages(hwId);

                    while (
                        Device.RemoveFromSystem(
                            devInfoSet,
                            hwId,
                            false)
                    );
                }
            }
        }