Пример #1
0
 public bool install(string InfFileName, string HardwareID, int RebootRequired, string Port, string AT, string MaximumPortSpeed)
 {
     if (File.Exists(InfFileName))
     {
         if (!this.FindExistingDevice(HardwareID))
         {
             this.print(">>枚举设备完毕!", 4);
             this.print(string.Format(">>未找到硬件ID:{0},正准备注册该ID.......", HardwareID));
             if (!this.InstallRootEnumeratedDriver(InfFileName, HardwareID, RebootRequired, Port, AT, MaximumPortSpeed))
             {
                 return(false);
             }
         }
         else
         {
             this.print(">>枚举设备完毕!", 4);
             this.print(string.Format(">>找到硬件ID:{0},设备已安装,正准备更新设备.......", HardwareID));
             if (InstallMainClass.UpdateDriverForPlugAndPlayDevices((IntPtr)0, HardwareID, InfFileName, 1, ref RebootRequired))
             {
                 this.print(">>更新设备成功!", 2);
             }
             else
             {
                 this.print(">>更新设备失败!", 3);
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         InstallMainClass.bw.ReportProgress(3, "发生错误:安装信息文件丢失!!!");
         return(false);
     }
 }
Пример #2
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);
            }
        }
Пример #3
0
        private void BW_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;
            bool             argument         = (bool)e.Argument;
            string           str = string.Concat(Directory.GetCurrentDirectory(), "\\MDMSaro.inf");
            InstallMainClass installMainClass = new InstallMainClass();

            backgroundWorker.ReportProgress(1, string.Concat(">>INF PATH ", str, "\r\n"));
            InstallMainClass.bw = backgroundWorker;
            if (!argument)
            {
                if (installMainClass.install(str, "SaroCDMA", 0, SetupForm.sfm.comboBox1.SelectedItem.ToString(), "", "115200"))
                {
                    backgroundWorker.ReportProgress(2, ">>安装成功!!!\r\n");
                    backgroundWorker.ReportProgress(1, ">>正在创建新连接!!!\r\n");
                    PigTao pigTao = new PigTao();
                    int    num    = pigTao.CreatConnect("SaroCDMA", "#777", "桑荣 6200 CDMA modem", "CARD", "CARD");
                    if (num == 0 || num == 183)
                    {
                        backgroundWorker.ReportProgress(2, ">>创建新连接成功,拨号名SaroCDMA!!!\r\n");
                        backgroundWorker.ReportProgress(1, ">>正在设置SaroCDMA为默认连接\r\n");
                        SetDefaultConnection setDefaultConnection = new SetDefaultConnection();
                        setDefaultConnection.Set("SaroCDMA");
                        backgroundWorker.ReportProgress(2, ">>设置成功!\r\n");
                        PBK pBK = new PBK();
                        pBK.DO("[SaroCDMA]");
                        backgroundWorker.ReportProgress(2, ">>所有任务安装设置成功!!!");
                        return;
                    }
                    else
                    {
                        backgroundWorker.ReportProgress(3, string.Concat(">>创建新连接失败,出错信息:", num.ToString()));
                        backgroundWorker.ReportProgress(3, ">>安装中止!!!");
                        return;
                    }
                }
                else
                {
                    backgroundWorker.ReportProgress(3, ">>安装失败!!!");
                    return;
                }
            }
            else
            {
                if (installMainClass.install(str, "SaroGPRS", 0, SetupForm.sfm.comboBox1.SelectedItem.ToString(), "at+cgdcont=1,\"ip\",\"cmnet\"", "57600"))
                {
                    backgroundWorker.ReportProgress(2, ">>安装成功!!!\r\n");
                    backgroundWorker.ReportProgress(1, ">>正在创建新连接!!!\r\n");
                    PigTao pigTao1 = new PigTao();
                    int    num1    = pigTao1.CreatConnect("SaroGPRS", "*99***1#", "桑荣 3100 GPRS modem", "", "");
                    if (num1 == 0 || num1 == 183)
                    {
                        backgroundWorker.ReportProgress(2, ">>创建新连接成功,拨号名SaroGPRS!!!\r\n");
                        backgroundWorker.ReportProgress(1, ">>正在设置SaroGPRS为默认连接\r\n");
                        SetDefaultConnection setDefaultConnection1 = new SetDefaultConnection();
                        setDefaultConnection1.Set("SaroGPRS");
                        backgroundWorker.ReportProgress(2, ">>设置成功!\r\n");
                        PBK pBK1 = new PBK();
                        pBK1.DO("[SaroGPRS]");
                        backgroundWorker.ReportProgress(2, ">>所有任务安装设置成功!!!");
                        return;
                    }
                    else
                    {
                        backgroundWorker.ReportProgress(3, string.Concat(">>创建新连接失败,出错信息:", num1.ToString()));
                        backgroundWorker.ReportProgress(3, ">>安装中止!!!");
                        return;
                    }
                }
                else
                {
                    backgroundWorker.ReportProgress(3, ">>安装失败!!!");
                    return;
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
            }
        }