Sometimes developers want to list down or identify the Devices in a Windows machine programmatically. How do enumerate the devices and resources quickly? Don’t know how to do it? Don’t worry. MiTec’s System Information Management Suite’s component helps to do that effectively, and we will learn how to retrieve devices similar to Windows device manager.
Platforms: Windows.
Installation Steps:
You can easily install this Component Suite from GetIt Package Manager. The steps are as follows.
- Navigate In RAD Studio IDE->Tools->GetIt Package Manager->select Components in Categories->Components->Trail -MiTec system Information Component Suite 14.3 and click Install Button.
- Read the license and Click Agree All. An Information dialog saying ‘Requires a restart of RAD studio at the end of the process. Do you want to proceed? click yes and continue.
- It will download the plugin and installs it. Once installed Click Restart now.
How to run the Demo app:
- Navigate to the System Information Management Suite trails setup, Demos folder which is installed during Get It installation e.g) C:UsersDocumentsEmbarcaderoStudio21.0CatalogRepositoryMiTeC-14.3DemosDelphi13
- Open the DeviceBrowser project in RAD studio 10.4.1 compile and Run the application.
- This Demo App shows how to list down the known windows devices, device resources, enumerate among them and access its properties.
Components used in MSIC DeviceBrowser Demo App:
- TMiTeC_Devices Enumerates all known devices and their properties. (It does the same as Windows Device Manager)
- 2 TTabsheet’s one for viewing Devices list in TTreeView and other for viewing Resources in TListView.
- TButton to view the details, resources of the device in a new child form.
Implementation Details:
- An instance Devices of TMiTeC_Devices Call RefreshData where list of Windows devices was added to the tree node by a loop through DeviceCount property. A list of resources was added to the listview items from the GetResourceList procedure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
procedure Twnd_db_Main.RefreshData; var i,c,ii: integer; r,n: TTreeNode; lcn,cn,dn: string; pi: PInteger; RL: TResourceList; ilh: THandle; g: TGUID; begin Devices.RefreshData; lcn:=''; with Devices, Tree,Items do begin c:=DeviceCount-1; BeginUpdate; while Count>0 do begin if Assigned(Items[Count-1].Data) then FreeMem(Items[Count-1].Data); Delete(Items[Count-1]); end; r:=Add(nil,GetMachine); r.ImageIndex:=0; r.SelectedIndex:=r.ImageIndex; n:=nil; for i:=0 to c do begin if (Trim(Devices[i].ClassDesc)<>'') then cn:=Devices[i].ClassDesc else cn:=Devices[i].ClassName; if not Assigned(n) or not SameText(Devices[i].ClassName,lcn) then begin lcn:=Devices[i].ClassName; n:=AddChild(r,cn); g:=Devices[i].ClassGUID; SetupDiGetClassImageIndex(spid,g,ii); n.ImageIndex:=ii; n.SelectedIndex:=n.ImageIndex; end; dn:=Devices[i].Name; with AddChild(n,dn) do begin ImageIndex:=n.ImageIndex; SelectedIndex:=ImageIndex; new(pi); pi^:=i; Data:=pi; end; n.AlphaSort; end; r.AlphaSort; r.Expand(False); EndUpdate; end; tsDevRes.TabVisible:=Devices.LiveData; bRes.Visible:=Devices.LiveData; if Devices.LiveData then with Devices, ResList, Items do begin GetResourceList(RL); BeginUpdate; try Clear; for i:=0 to High(RL) do with Add do begin Caption:=RL[i].Resource; SubItems.Add(ResourceShareStr(RL[i].Share)); SubItems.Add(RL[i].Device); g:=RL[i].DeviceClassGUID; SetupDiGetClassImageIndex(spid,g,ii); ImageIndex:=ii; end; finally EndUpdate; end; end; end; |
- On clicking the Properties button for the selected tree node item, its properties such as Class Description, GUID, Manufacturer, Hardware ID etc were displayed in a child form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
procedure Twnd_db_Main.cmProps(Sender: TObject); var dr: TDevice; i,ii: integer; h: HICON; g: TGUID; begin if Assigned(Tree.Selected) and (Tree.Selected.Level=2) then with Tdlg_db_Detail.Create(self) do begin lv.items.clear; i:=PInteger(Tree.Selected.Data)^; dr:=Devices.Devices[i]; g:=dr.ClassGUID; SetupDiLoadClassIcon(g,h,ii); Icon.Picture.Icon.Handle:=h; eName.Text:=dr.Name; with lv.Items.Add do begin Caption:='Class Name'; Subitems.Add(dr.ClassName); ImageIndex:=-3; end; with lv.Items.Add do begin Caption:='Class Description'; Subitems.Add(dr.ClassDesc); end; with lv.Items.Add do begin Caption:='Class GUID'; Subitems.Add(dr.GUID); end; with lv.Items.Add do begin Caption:='Registry Key'; Subitems.Add(dr.RegKey); end; with lv.Items.Add do begin Caption:='Manufacturer'; Subitems.Add(dr.Manufacturer); end; with lv.Items.Add do begin Caption:='Hardware ID'; Subitems.Add(dr.HardwareID); end; with lv.Items.Add do begin Caption:='SymbolicLink'; Subitems.Add(dr.SymbolicLink); end; with lv.Items.Add do begin Caption:='Location'; Subitems.Add(Format('%s',[dr.Location])); end; with lv.Items.Add do begin Caption:='PCI Number'; Subitems.Add(Format('%d',[dr.PCINumber])); end; with lv.Items.Add do begin Caption:='Device Number'; Subitems.Add(Format('%d',[dr.DeviceNumber])); end; with lv.Items.Add do begin Caption:='Function Number'; Subitems.Add(Format('%d',[dr.FunctionNumber])); end; with lv.Items.Add do begin Caption:='Vendor ID'; Subitems.Add(Format('%4.4x',[dr.VendorID])); end; with lv.Items.Add do begin Caption:='Device ID'; Subitems.Add(Format('%4.4x',[dr.DeviceID])); end; with lv.Items.Add do begin Caption:='SubSystem'; Subitems.Add(Format('%8.8x',[dr.SubSysID])); end; with lv.Items.Add do begin Caption:='Revision'; Subitems.Add(Format('%2.2x',[dr.Revision])); end; with lv.Items.Add do begin Caption:=''; ImageIndex:=-2; end; with lv.Items.Add do begin Caption:='Driver Description'; SubItems.Add(dr.Driver); ImageIndex:=-3; end; with lv.Items.Add do begin Caption:='Driver Version'; SubItems.Add(dr.DriverVersion); end; with lv.Items.Add do begin Caption:='Driver Date'; SubItems.Add(dr.DriverDate); end; with lv.Items.Add do begin Caption:='Driver Provider'; SubItems.Add(dr.DriverProvider); end; with lv.Items.Add do begin Caption:='Driver GUID'; SubItems.Add(dr.DriverKey); end; with lv.Items.Add do begin Caption:='Image Path'; SubItems.Add(dr.ImagePath); end; with lv.Items.Add do begin Caption:=''; ImageIndex:=-2; end; with lv.Items.Add do begin Caption:='Service Name'; if dr.ServiceName='' then SubItems.Add(dr.Service) else SubItems.Add(dr.ServiceName); ImageIndex:=-3; end; with lv.Items.Add do begin Caption:='Service Group'; SubItems.Add(dr.ServiceGroup); end; with lv.Items.Add do begin Caption:=''; ImageIndex:=-2; end; with lv.Items.Add do begin Caption:='Install ID'; SubItems.Add(dr.InstallID); ImageIndex:=-3; end; with lv.Items.Add do begin Caption:='Install Date'; SubItems.Add(DateTimeToStrDef(dr.InstallDate)); end; with lv.Items.Add do begin Caption:='First Install Date'; SubItems.Add(DateTimeToStrDef(dr.FirstInstallDate)); end; with lv.Items.Add do begin Caption:='Last Arrival Date'; SubItems.Add(DateTimeToStrDef(dr.LastArrivalDate)); end; with lv.Items.Add do begin Caption:='Last Removal Date'; SubItems.Add(DateTimeToStrDef(dr.LastRemovalDate)); end; showmodal; DestroyIcon(h); free; end; end; |
- Similarly, On Clicking Resources , the selected tree node TDeviceResources properties were shown.
These simple steps is sufficient to retrieve Devices and its properties in your application. Use this MiTeC component suite and get the job done quickly.
With the use of Windows tools for developers, you can easily browse your Windows devices from your Delphi app with various powerful components. Try your Free Trial here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition