Menu
Home
Products
  WmiSet Components
    Release History
    TWmiQuery
    TWmiProcessControl
    TWmiOs
    TWmiConnection
    TWmiStorageInfo
    TWmiDiskQuotaControl
    TWmiSystemEvents
    TWmiMethod
    TWmiPerformanceMonitor
  NTSet components
  "How to" zone
  Shareware
  Full version
  Archive
  NTSet
  WmiSet
Contact us
Advanced search
Site map

Quick search

Advanced search

New version notify
e-mail address: Subscribe Unsubscribe
Privacy statement
TWmiRegistry component

TWmiRegistry is a part of WmiSet Component Collection for Delphi, C++Builder. This VCL component allows for reading and writing the system registry on a local or remote computer. It is build as a wrapper around StrRegProv class, which comes with operating system and serves as a standard registry provider in WMI. TWmiregistry component can read/write data of these registry types:
  • REG_BINARY
  • REG_DWORD
  • REG_EXPAND_SZ
  • REG_MULTI_SZ
  • REG_SZ
This component acts pretty much like standard TRegistry component from Delphi VCL. It has all the same methods to read or write data: ReadXXX and WriteXXX. These methods are compatible with those of TRegistry: one can use the TWmiRegistry component to write to the system registry and the TRegistry class to read the values back. There are several important differences between TRegistry and TWmiRegistry:
  • The TWmiRegistry.ReadBinaryData method will raise an exception if the actual type of data in the registry is not REG_BINARY.
  • The TWmiRegistry component allows connecting to remote computer's registry using different credentials than the currently logged on user. This may be important for the administrative tasks.
  • The TWmiRegistry component can be used at design time.
  • The TWmiRegistry provides the methods to read and write wide strings (unicode). Use ReadStringW, WriteStringW, ReadMultiString, WriteMultiStringW methods.
TWmiRegistry Demo
The WmiSet collection comes with example that demonstrates how to use TWmiRegistry component. The example closely resembles Registry Editor utility that is available in Windows. Click here to download the compiled executable.
Typical tasks
These examples assume that TWmiRegistry component was dropped on the form at the design time. If this is not the case, you may create the component at the run time. This will require that WmiRegistry unit is included into Uses clause:
procedure TForm1.Test;
var
  WmiRegistry1: TWmiRegistry;
begin
  WmiRegistry1 := TWmiRegistry.Create(nil);
  try
    ...
  finally
    WmiRegistry1.Free;
  end;
end;
            
When testing the examples, make sure to replace dummy user names and passwords with the real ones.

How to create a new registry key on a remote computer?
with WmiRegistry1 do
begin 
  MachineName := '10.8.26.69';
  Credentials.UserName := 'mydomain\JohnSmith';
  Credentials.Password := 'MyPassword';
  RootKey := HKEY_LOCAL_MACHINE;
  Active := true;
  try
    CreateKey('\SOFTWARE\MyNewTestKey');
  finally
    Active := false;
  end;
end;
            
How to enumerate all the sub-keys of a known key on a local computer?
procedure TForm1.ListKeys;
var
  i: integer;
  vList: TStrings;
begin
  vList := TStringList.Create;
  WmiRegistry1.Currentpath := 'SOFTWARE\';
  WmiRegistry1.Active := true;
  try
    WmiRegistry1.ListSubKeys(vList);
    for i := 0 to vList.Count - 1 do
    begin
       ...
    end;
  finally
    vList.Free;
    WmiRegistry1.Active := false;
  end;
end;
            
How to read registry values on a local computer?
procedure TForm1.TestListValues;
var
  i: integer;
  vList: TStrings;
  vValue: Variant;
begin
  vList := TStringList.Create;
  WmiRegistry1.CurrentPath := 
      'SOFTWARE\Borland\Delphi\6.0';
  WmiRegistry1.Active := true;
  try
    // obtain list of all the values
    WmiRegistry1.ListValues(vList);
    for i := 0 to vList.Count - 1 do
    begin
      // read each value as variant
      vValue := WmiRegistry1.ReadValue(vList[i]);
      ...
    end;
  finally
    vList.Free;
    WmiRegistry1.Active := false;
  end;
end;