Do you need to access management information in an enterprise environment from your Delphi Application? Don’t know where to start with? Don’t worry. MiTec’s System Information Management Suite’s component helps you access systems, applications, networks, devices, and other managed components with less code, and we will learn how to use MiTeC_WbemScripting_TLB in this blog post. For more info on Windows Management Instrumentation (WMI) check here
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.3DemosDelphi7
- Open the WMIDemo project in RAD studio 10.4.1 compile and Run the application.
- This Demo App shows how to use MiTeC_WbemScripting_TLB’s ISWbemServices and list the Computer, Operating system, Processor, Memory, Storage etc.
Components used in MSIC WMIDemo App:
- 3 TEdit‘s to provide machine name, username, password in a enterprise network which helps to connect and access the management information.
- TTreeView to show the Computer, Operating system, Processor, Memory, Storage etc. in a tree view.
- TButton to refresh and close.
Implementation Details:
- Connect to the Machine from the provided machine, username and password details using WMIConnect. An interface variable of type ISWbemServices’s reference is acquired during this connect operation.
- A WMICommand call helps to retrieve the system information such as operating system, processor, etc. as shown below.
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 |
procedure TForm1.RefreshData; var i,j,k: Integer; r,n,c: TTreeNode; wmiServices: ISWbemServices; wmi,wmi1,wmi2,wmi3: TInstances; s,s1,s2: string; v: Int64; begin Screen.Cursor:=crHourglass; Tree.Hide; Tree.Items.BeginUpdate; Update; try Tree.Items.Clear; if not WMIConnect(eMachine.Text,eUser.Text,ePwd.Text,Rootnamespace,wmiServices) then Exit; WMICommand(wmiServices,'Win32_ComputerSystem',wmi1); r:=Tree.Items.AddChild(nil,'Computer'); n:=Tree.Items.AddChild(r,Format('%s - %s',[GetInstancePropertyValue(wmi1,'Name'), GetInstancePropertyValue(wmi1,'UserName')])); WMICommand(wmiServices,'Win32_OperatingSystem',wmi); r:=Tree.Items.AddChild(nil,'Operating system'); n:=Tree.Items.AddChild(r,GetInstancePropertyValue(wmi,'Name')); WMICommand(wmiServices,'Win32_Processor',wmi); r:=Tree.Items.AddChild(nil,'CPU'); for i:=0 to High(wmi) do begin n:=Tree.Items.AddChild(r,Format('%s - %s MHz',[GetInstancePropertyValue(wmi,'Name'),GetInstancePropertyValue(wmi,'CurrentClockSpeed')])); c:=Tree.Items.AddChild(n,GetInstancePropertyValue(wmi,'Description')); end; r:=Tree.Items.AddChild(nil,'Memory'); try v:=StrToInt64(GetInstancePropertyValue(wmi1,'TotalPhysicalMemory')) except v:=0 end; n:=Tree.Items.AddChild(r,Format('%d MB',[v shr 20])); WMICommand(wmiServices,'Win32_DiskDrive',wmi); r:=Tree.Items.AddChild(nil,'Storage'); for i:=0 to High(wmi) do begin try v:=StrToInt64(GetInstancePropertyValue(wmi,'Size',i)) except v:=0 end; n:=Tree.Items.AddChild(r,Format('%s - %d MB',[GetInstancePropertyValue(wmi,'Model',i), v shr 20])); WMICommand(wmiServices,Format('select * from Win32_DiskPartition where DiskIndex=%s',[GetInstancePropertyValue(wmi,'Index',i)]),wmi1); WMICommand(wmiServices,'Win32_LogicalDiskToPartition',wmi2); for j:=0 to High(wmi1) do begin for k:=0 to High(wmi2) do begin s1:=GetInstancePropertyValue(wmi1,'DeviceID',j); s2:=GetInstancePropertyValue(wmi2,'Antecedent',k); if Pos(s1,s2)>0 then begin s:=GetInstancePropertyValue(wmi2,'Dependent',k); s:=Copy(s,Pos(':"',s)-1,2); WMICommand(wmiServices,Format('select * from Win32_LogicalDisk where DeviceId=''%s''',[s]),wmi3); try v:=StrToInt64(GetInstancePropertyValue(wmi,'Size',i)) except v:=0 end; c:=Tree.Items.AddChild(n,Format('%s [%s] - %d MB - %s',[s,GetInstancePropertyValue(wmi3,'VolumeName',0),v shr 20,GetInstancePropertyValue(wmi3,'FileSystem',0)])); end; end; end; end; WMICommand(wmiServices,'Win32_CDROMDrive',wmi); for i:=0 to High(wmi) do begin n:=Tree.Items.AddChild(r,GetInstancePropertyValue(wmi,'Name',i)); c:=Tree.Items.AddChild(n,GetInstancePropertyValue(wmi,'Id',i)); end; WMICommand(wmiServices,'Win32_TapeDrive',wmi); for i:=0 to High(wmi) do begin n:=Tree.Items.AddChild(r,GetInstancePropertyValue(wmi,'Name',i)); c:=Tree.Items.AddChild(n,GetInstancePropertyValue(wmi,'Id',i)); end; WMICommand(wmiServices,'Win32_VideoController',wmi); r:=Tree.Items.AddChild(nil,'Graphics'); try v:=StrToInt(GetInstancePropertyValue(wmi,'AdapterRAM')) except v:=0 end; n:=Tree.Items.AddChild(r,Format('%s - %d MB',[GetInstancePropertyValue(wmi,'Name'),v shr 20])); WMICommand(wmiServices,'Win32_DesktopMonitor',wmi); r:=Tree.Items.AddChild(nil,'Monitor'); for i:=0 to High(wmi) do begin n:=Tree.Items.AddChild(r,Format('%s - (%s x %s) px',[GetInstancePropertyValue(wmi,'Name'), GetInstancePropertyValue(wmi,'ScreenWidth'), GetInstancePropertyValue(wmi,'ScreenHeight')])); end; WMICommand(wmiServices,'Win32_SoundDevice',wmi); r:=Tree.Items.AddChild(nil,'Audio'); for i:=0 to High(wmi) do begin n:=Tree.Items.AddChild(r,GetInstancePropertyValue(wmi,'Name',i)); end; WMICommand(wmiServices,'Win32_NetworkAdapter',wmi); r:=Tree.Items.AddChild(nil,'Network'); for i:=0 to High(wmi) do begin WMICommand(wmiServices,Format('select * from Win32_NetworkAdapterConfiguration where Caption=''%s''',[GetInstancePropertyValue(wmi,'Caption',i)]),wmi1); s1:=GetInstancePropertyValue(wmi,'MACAddress',i); s2:=GetInstancePropertyValue(wmi1,'IPAddress',0); if not SameText(s1,'NULL') and not SameText(s2,'NULL') then begin n:=Tree.Items.AddChild(r,GetInstancePropertyValue(wmi,'Name',i)); c:=Tree.Items.AddChild(n,s1); c:=Tree.Items.AddChild(n,s2); end; end; WMICommand(wmiServices,'Win32_Printer',wmi); r:=Tree.Items.AddChild(nil,'Printers'); for i:=0 to High(wmi) do begin n:=Tree.Items.AddChild(r,GetInstancePropertyValue(wmi,'Name',i)); end; Tree.FullExpand; Tree.Items.GetFirstNode.MakeVisible; finally WMIDisconnect(wmiServices); Finalize(wmi); Finalize(wmi1); Finalize(wmi2); Tree.Items.EndUpdate; Tree.Show; Screen.Cursor:=crdefault; end; end; |
Developers can use this MiTeC Component suite and able to obtain management data to automate administrative tasks on remote computers quickly.
With the use of a Windows IDE, Windows management instrumentation is made easy in your Delphi apps using a component suite. Try your Free Trial here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Please stop spamming this blog with multiple articles about the same 3. party components.
You have sent 6 articles about your 3. party components since 1th february.