Link to home
Start Free TrialLog in
Avatar of retinax
retinax

asked on

Device Manager in VB

I want to make Device Manager in VB. I found the similar code in VC++ in the following site
http://www.codeproject.com/system/DevMgr.asp

But I want to develop the same thing in VB
Avatar of graye
graye
Flag of United States of America image

You can get a lot of that functionality by using Windows Management Instrumentation (WMI).

I've got quite a few examples in VB.Net (but I assume you're asking for VB6?)
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, sorry, EnumAllDevice function should be


Public Function EnumAllDevices(tv As TreeView)
   Dim hDevInfo As Long
   Dim gd As Guid
   Dim devinfo As SP_DEVINFO_DATA
   Dim ifData As SP_DEVICE_INTERFACE_DATA
   Dim ifDetails As SP_DEVICE_INTERFACE_DETAIL_DATA
   Dim nCount As Long, n As Long
   Dim bResult As Boolean
   Dim sClass As String, sGUID, sDevice As String
   
   hDevInfo = SetupDiGetClassDevs(ByVal 0&, vbNullString, 0, DIGCF_PRESENT Or DIGCF_PROFILE Or DIGCF_ALLCLASSES)
   tv.Nodes.Add , , "Root", Environ$("COMPUTERNAME")
   If hDevInfo = INVALID_HANDLE_VALUE Then Exit Function
   nCount = 0: bResult = True
   devinfo.cbSize = Len(devinfo)

   Do While bResult
      n = SetupDiEnumDeviceInfo(hDevInfo, nCount, devinfo)
      bResult = CBool(n)
      If bResult Then
         sGUID = GetSetupRegSetting(hDevInfo, devinfo, SPDRP_CLASSGUID)
         If Not NodeExists(tv, sGUID) Then
            sClass = GetSetupRegSetting(hDevInfo, devinfo, SPDRP_CLASS)
            tv.Nodes.Add tv.Nodes("Root"), tvwChild, sGUID, sClass
         End If
         sDevice = GetSetupRegSetting(hDevInfo, devinfo, SPDRP_FRIENDLYNAME)
         If sDevice = "" Then sDevice = GetSetupRegSetting(hDevInfo, devinfo, SPDRP_DEVICEDESC)
         tv.Nodes.Add tv.Nodes(sGUID), tvwChild, "", sDevice
      End If
      nCount = nCount + 1
   Loop
   Call SetupDiDestroyDeviceInfoList(hDevInfo)
   tv.Nodes("Root").Expanded = True
   EnumAllDevices = nCount
End Function
Forced accept.

Computer101
EE Admin