Exemple #1
0
        private bool FindExistingDevice(string HardwareID)
        {
            this.print(">>正在准备枚举设备...........", 4);
            InstallMainClass.SP_DEVINFO_DATA sPDEVINFODATum = new InstallMainClass.SP_DEVINFO_DATA();
            InstallMainClass._GUID           __GUID         = new InstallMainClass._GUID();
            IntPtr intPtr = InstallMainClass.SetupDiGetClassDevs(ref __GUID, 0, (IntPtr)0, 6);

            if ((int)intPtr == -1)
            {
                this.print("错误:无法得到设备的DeviceInfoSet", 3);
            }
            bool flag = false;

            sPDEVINFODATum.cbSize = 28;
            for (int i = 0; InstallMainClass.SetupDiEnumDeviceInfo(intPtr, i, ref sPDEVINFODATum); i++)
            {
                int    num      = 0;
                byte[] numArray = null;
                int    num1     = 0;
                while (!InstallMainClass.SetupDiGetDeviceRegistryProperty(intPtr, ref sPDEVINFODATum, 1, ref num, numArray, num1, ref num1) && InstallMainClass.GetLastError() != 13)
                {
                    if (InstallMainClass.GetLastError() != 122)
                    {
                        this.print("错误:无法得到设备的RegistryProperty,正在销毁DeviceInfo.......", 3);
                        InstallMainClass.SetupDiDestroyDeviceInfoList(intPtr);
                        this.print("销毁DeviceInfo成功,安装中止", 3);
                    }
                    else
                    {
                        numArray = new byte[num1];
                    }
                }
                if (InstallMainClass.GetLastError() != 13)
                {
                    string str = Encoding.Default.GetString(numArray, 0, num1 - 2);
                    this.print(str);
                    if (str != HardwareID)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        break;
                    }
                }
            }
            if (InstallMainClass.GetLastError() == 0)
            {
                return(flag);
            }
            else
            {
                return(flag);
            }
        }
Exemple #2
0
        private bool InstallRootEnumeratedDriver(string InfFile, string HardwareID, int RebootRequired, string Port, string AT, string MaximumPortSpeed)
        {
            InstallMainClass.SP_DEVINFO_DATA sPDEVINFODATum = new InstallMainClass.SP_DEVINFO_DATA();
            InstallMainClass._GUID           __GUID         = new InstallMainClass._GUID();
            byte[] numArray = new byte[32];
            int    num      = 0;
            string str      = "";

            if (InstallMainClass.SetupDiGetINFClass(InfFile, ref __GUID, numArray, (int)numArray.Length, ref num))
            {
                for (int i = 0; i < num - 1; i++)
                {
                    char chr = (char)numArray[i];
                    str = string.Concat(str, chr.ToString());
                }
                this.print(">>正在创建设备信息列表");
                IntPtr intPtr = InstallMainClass.SetupDiCreateDeviceInfoList(ref __GUID, (IntPtr)0);
                sPDEVINFODATum.cbSize = 28;
                if (InstallMainClass.SetupDiCreateDeviceInfo(intPtr, numArray, ref __GUID, "null", (IntPtr)0, 1, ref sPDEVINFODATum))
                {
                    this.print(">>创建设备信息列表成功!", 2);
                    byte[] bytes = Encoding.ASCII.GetBytes(HardwareID);
                    this.print(">>SetDeviceRegistryProperty.........");
                    if (InstallMainClass.SetupDiSetDeviceRegistryProperty(intPtr, ref sPDEVINFODATum, 1, bytes, HardwareID.Length + 2))
                    {
                        this.print(">>SetDeviceRegistryProperty成功!");
                        if (this.RegisterModem(intPtr, ref sPDEVINFODATum, Port, AT, MaximumPortSpeed))
                        {
                            this.print(">>正在安装驱动........");
                            if (InstallMainClass.UpdateDriverForPlugAndPlayDevices((IntPtr)0, HardwareID, InfFile, 1, ref RebootRequired))
                            {
                                return(true);
                            }
                            else
                            {
                                this.print(">>安装失败,正在移除设备", 3);
                                if (InstallMainClass.SetupDiCallClassInstaller(5, intPtr, ref sPDEVINFODATum))
                                {
                                    this.print(">>设备移除成功");
                                    return(false);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            if (InstallMainClass.SetupDiCallClassInstaller(5, intPtr, ref sPDEVINFODATum))
                            {
                                return(false);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        InstallMainClass.SetupDiDestroyDeviceInfoList(intPtr);
                        this.print("失败!,已销毁设备信息列表", 3);
                        return(false);
                    }
                }
                else
                {
                    this.print(">>创建设备信息列表失败!", 3);
                    InstallMainClass.SetupDiDestroyDeviceInfoList(intPtr);
                    return(false);
                }
            }
            else
            {
                this.print(">>读取inf文件出错!!!", 3);
                return(false);
            }
        }