コード例 #1
0
ファイル: SetupDi.cs プロジェクト: SPOOCQ/ghostbuster
        /// <summary>
        /// Get Device Instance Id.
        /// </summary>
        /// <param name="DeviceInfoSet"></param>
        /// <param name="DeviceInfoData"></param>
        /// <returns></returns>
        internal String GetDeviceInstanceId(IntPtr DeviceInfoSet, SetupDi.SP_DEVINFO_DATA DeviceInfoData)
        {
            StringBuilder strId         = new StringBuilder(0);
            Int32         iRequiredSize = 0;
            Int32         iSize         = 0;

            /*Int32 iRet = */
            SetupDi.SetupDiGetDeviceInstanceId(DeviceInfoSet, ref DeviceInfoData, strId, iSize, ref iRequiredSize);
            strId = new StringBuilder(iRequiredSize);
            iSize = iRequiredSize;

            if (SetupDi.SetupDiGetDeviceInstanceId(DeviceInfoSet, ref DeviceInfoData, strId, iSize, ref iRequiredSize) == 1)
            {
                return(strId.ToString());
            }
            return(String.Empty);
        }
コード例 #2
0
ファイル: SetupDi.cs プロジェクト: SPOOCQ/ghostbuster
        /// <summary>
        /// Retrieve the Description of a DeviceClass.
        /// </summary>
        /// <param name="deviceinfo"></param>
        /// <param name="guid"></param>
        /// <returns></returns>
        internal static Boolean GetClassDescriptionFromGuid(ref DeviceInfo deviceinfo, Guid guid)
        {
            deviceinfo.deviceclass = String.Empty;

            StringBuilder strClassDesc  = new StringBuilder(0);
            Int32         iRequiredSize = 0;
            Int32         iSize         = 0;
            Int32         iRet          = SetupDi.SetupDiGetClassDescription(ref guid, strClassDesc, iSize, ref iRequiredSize);

            strClassDesc = new StringBuilder(iRequiredSize);
            iSize        = iRequiredSize;
            iRet         = SetupDi.SetupDiGetClassDescription(ref guid, strClassDesc, iSize, ref iRequiredSize);
            if (iRet == 1)
            {
                deviceinfo.deviceclass = strClassDesc.ToString();
            }

            return(String.IsNullOrEmpty(deviceinfo.deviceclass));
        }
コード例 #3
0
ファイル: SetupDi.cs プロジェクト: SPOOCQ/ghostbuster
        /// <summary>
        /// Retrieve and decode the device status.
        /// </summary>
        /// <param name="deviceinfo"></param>
        /// <param name="deviceinfoset"></param>
        /// <param name="deviceinfodata"></param>
        /// <returns></returns>
        internal static Boolean GetDeviceStatus(ref DeviceInfo deviceinfo, IntPtr deviceinfoset, ref SetupDi.SP_DEVINFO_DATA deviceinfodata)
        {
            StringBuilder descriptionBuf = new StringBuilder(256);
            int           length         = descriptionBuf.Capacity;

            //Assume All is ok
            deviceinfo.status   = 0;
            deviceinfo.problem  = 0;
            deviceinfo.service  = false;
            deviceinfo.disabled = false;
            deviceinfo.ghosted  = false;

            if (SetupDi.SetupDiGetDeviceInstanceId(deviceinfoset, ref deviceinfodata, descriptionBuf, length, ref length) != 0)
            {
                int aDevInst = deviceinfodata.DevInst;
                int aStatus  = 0;
                int aProblem = 0;

                if (CM_Get_DevNode_Status(ref aStatus, ref aProblem, aDevInst, (int)0) == CR_SUCCESS)
                {
                    deviceinfo.status = aStatus;

                    if ((aStatus & (int)DN.DN_HAS_PROBLEM) != 0)
                    {
                        switch (aProblem)
                        {
                        case (int)CM_PROB.CM_PROB_DISABLED:
                        case (int)CM_PROB.CM_PROB_DISABLED_SERVICE:
                            deviceinfo.disabled = true;
                            break;

                        default:
                            break;
                        }
                    }
                    else if ((aStatus & ((int)DN.DN_DRIVER_LOADED | (int)DN.DN_STARTED)) != 0)
                    {
                        //return String.Format("0x{0:x8} - {1}", aStatus, "OK");
                    }
                    else if ((aStatus & ((int)DN.DN_DISABLEABLE)) != 0)
                    {
                        //
                    }
                    else
                    {
                        //
                    }
                }
                else
                {
                    //using (RegistryKey services = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Services"))
                    //{
                    //    if (services.OpenSubKey(deviceinfo.name) != null)
                    //        return String.Format("{0}", "Service");

                    //    //Also Scan All Services for DisplayNames....
                    //}
                    if (serviceslist.Contains(deviceinfo.name.ToLower()))
                    {
                        deviceinfo.service = true;
                    }
                    else
                    {
                        deviceinfo.ghosted = true;
                    }
                }

                return(true);
            }

            return(false);
        }