Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
 public static extern bool SetupDiSetDeviceRegistryProperty(IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData, int Property, byte[] PropertyBuffer, int PropertyBufferSize);
Exemplo n.º 3
0
 public static extern bool SetupDiRegisterDeviceInfo(IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData, int Flags, ref uint CompareProc, ref int CompareContext, ref InstallMainClass.SP_DEVINFO_DATA DupDeviceInfoData);
Exemplo n.º 4
0
 public static extern IntPtr SetupDiOpenDevRegKey(IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData, uint Scope, uint HwProfile, uint KeyType, uint samDesired);
Exemplo n.º 5
0
 public static extern bool SetupDiGetSelectedDriver(IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData, ref InstallMainClass.SP_DRVINFO_DATA DriverInfoData);
Exemplo n.º 6
0
 public static extern bool SetupDiEnumDeviceInfo(IntPtr DeviceInfoSet, int MemberIndex, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData);
Exemplo n.º 7
0
 public static extern IntPtr SetupDiCreateDevRegKey(IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData, uint Scope, uint HwProfile, uint KeyType, IntPtr InfHandle, string InfSectionName);
Exemplo n.º 8
0
 public static extern bool SetupDiCreateDeviceInfo(IntPtr DeviceInfoSet, byte[] DeviceName, ref InstallMainClass._GUID ClassGuid, string DeviceDescription, IntPtr hwndParent, int CreationFlags, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData);
Exemplo n.º 9
0
 public static extern bool SetupDiCallClassInstaller(int InstallFunction, IntPtr DeviceInfoSet, ref InstallMainClass.SP_DEVINFO_DATA DeviceInfoData);
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
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);
            }
        }