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 RegisterModem(IntPtr hdi, ref InstallMainClass.SP_DEVINFO_DATA pdevData, string Port, string AT, string MaximumPortSpeed)
        {
            this.print(">>正在注册Modem.........!");
            string str = "AttachedTo";
            int    num = 0;

            InstallMainClass.SP_DRVINFO_DATA sPDRVINFODATum = new InstallMainClass.SP_DRVINFO_DATA();
            uint num1 = 0;

            InstallMainClass.SP_DEVINFO_DATA sPDEVINFODATum = new InstallMainClass.SP_DEVINFO_DATA();
            this.print(">>注册设备信息.........!");
            if (InstallMainClass.SetupDiRegisterDeviceInfo(hdi, ref pdevData, 0, ref num1, ref num, ref sPDEVINFODATum))
            {
                this.print(">>注册设备信息成功!");
                IntPtr intPtr = InstallMainClass.SetupDiOpenDevRegKey(hdi, ref pdevData, 1, 0, 2, 0xf003f);
                if ((int)intPtr != -1 || InstallMainClass.GetLastError() != 0xe0000204)
                {
                    return(false);
                }
                else
                {
                    intPtr = InstallMainClass.SetupDiCreateDevRegKey(hdi, ref pdevData, 1, 0, 2, (IntPtr)0, null);
                    if (-1 != (int)intPtr)
                    {
                        this.print(string.Concat(">>正在绑定端口到", Port));
                        byte[] bytes = Encoding.ASCII.GetBytes(Port);
                        if (InstallMainClass.RegSetValueEx(intPtr, str, 0, 1, bytes, (uint)bytes.Length) == 0)
                        {
                            this.print(">>绑定端口成功");
                            this.print(">>正在初始化AT指今....");
                            if (AT != "")
                            {
                                byte[] numArray = Encoding.ASCII.GetBytes(AT);
                                if (InstallMainClass.RegSetValueEx(intPtr, "UserInit", 0, 1, numArray, (uint)numArray.Length) != 0)
                                {
                                    this.print(">>初始化AT指今失败", 3);
                                    return(false);
                                }
                            }
                            this.print(">>初始化AT指今成功");
                            this.print(">>正在设置最大端口速率....");
                            byte[] bytes1 = Encoding.ASCII.GetBytes(MaximumPortSpeed);
                            if (InstallMainClass.RegSetValueEx(intPtr, "MaximumPortSpeed", 0, 4, bytes1, (uint)bytes1.Length) == 0)
                            {
                                this.print(">>设置最大端口速率成功");
                                InstallMainClass.RegCloseKey(intPtr);
                                this.print(">>注册表相关健已关闭");
                                num1           = 0;
                                num            = 0;
                                sPDEVINFODATum = new InstallMainClass.SP_DEVINFO_DATA();
                                if (InstallMainClass.SetupDiRegisterDeviceInfo(hdi, ref pdevData, 0, ref num1, ref num, ref sPDEVINFODATum))
                                {
                                    this.print(">>注册Modem成功");
                                    InstallMainClass.SetupDiGetSelectedDriver(hdi, ref pdevData, ref sPDRVINFODATum);
                                    return(true);
                                }
                                else
                                {
                                    this.print(">>注册Modem失败", 3);
                                    return(false);
                                }
                            }
                            else
                            {
                                this.print(">>设置最大端口速率失败", 3);
                                return(false);
                            }
                        }
                        else
                        {
                            this.print(">>绑定端口失败", 3);
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                this.print(">>注册设备信息失败!");
                return(false);
            }
        }