Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4610180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:05:41+00:00 2026-05-22T01:05:41+00:00

I am using Delphi to remotely read and write the registry of a remote

  • 0

I am using Delphi to remotely read and write the registry of a remote machine. This works when my account on my machine has admin access to the remote machine.

However, I’d like to be able to specify a username / pwd when connecting to read the registry so I can connect with alternate credentials.

With the file-system I called the following (with the username and password) and was able to establish a connection to the remote system and perform filesystem related functions. However, this does not appear to work with the registry.

var
  netResource       : TNetResource;
begin

  FillChar(netResource, SizeOf(netResource), 0);
  netResource.dwScope := RESOURCE_GLOBALNET;
  netResource.dwType := RESOURCETYPE_DISK;
  netResource.dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;
  netResource.dwUsage := RESOURCEUSAGE_CONNECTABLE;
  netResource.lpRemoteName := PChar('\\192.168.1.105\IPC$');

  WNetAddConnection2(netResource, PChar(password), PChar(username), 0);
end;

…

And here is the example of the function I’d like to be able to call, but specify the credentials with access to the remote machine:

procedure TForm1.SetWallpaperKey() ;
var
   reg:TRegistry;
begin
   reg:=TRegistry.Create;

   with reg do begin
    try
     if RegistryConnect('192.168.1.105') then
       if OpenKey('\Control Panel\desktop', False) then begin
       //change wallpaper and tile it
        reg.WriteString ('Wallpaper','c:\windows\CIRCLES.bmp') ;
        reg.WriteString ('TileWallpaper','1') ;
        //disable screen saver//('0'=disable, '1'=enable)
        reg.WriteString('ScreenSaveActive','0') ;
       end
    finally
      reg.Free;
    end;
   end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:05:42+00:00Added an answer on May 22, 2026 at 1:05 am

    Mick , i can’t resist give you a WMI solution for you problem 😉 , the wmi have a class called StdRegProv which allow you to access the registry in local and remote machines. A key point is the namespace where the class is located, that depends of the version of windows installed in the remote machine. so for Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0, and Windows Me/98/95 the StdRegProv class is available in the root\default namespace and for others versions like windows Vista/7 the namespace is root\CIMV2.

    Now to configure the credentials to access the registry, you must set these values in the SWbemLocator.ConnectServer method in this way :

    FSWbemLocator.ConnectServer(Server, 'root\default', User, Pass);
    

    Another impor point is which this class just exposes methods to access the registry not properties, so you cannot use a wmi query, instead you must execute wmi methods.

    check the next samples to see how it works.

    checking if you have permissions over a key

    uses
      Windows,
      SysUtils,
      ActiveX,
      ComObj;
    
    // The CheckAccess method verifies that the user possesses the specified
    // permissions. The method returns a uint32 which is 0 if successful or some other
    // value if any other error occurred.
    
    procedure  Invoke_StdRegProv_CheckAccess;
    const
      Server = '192.168.52.128';
      User   = 'Administrator';
      Pass   = 'password';
    var
      FSWbemLocator   : OLEVariant;
      FWMIService     : OLEVariant;
      FWbemObjectSet  : OLEVariant;
      FInParams       : OLEVariant;
      FOutParams      : OLEVariant;
    begin
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      //http://msdn.microsoft.com/en-us/library/aa393664%28v=vs.85%29.aspx
      //StdRegProv is preinstalled in the WMI namespaces root\default and root\cimv2.
      //Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0, and Windows Me/98/95:  StdRegProv is available only in root\default namespace.
      FWMIService   := FSWbemLocator.ConnectServer(Server, 'root\default', User, Pass);
      //For Windows Vista or Windows 7 you must use the  root\CIMV2 namespace
      //FWMIService   := FSWbemLocator.ConnectServer(Server, 'root\CIMV2', User, Pass);
      FWbemObjectSet:= FWMIService.Get('StdRegProv');
      FInParams     := FWbemObjectSet.Methods_.Item('CheckAccess').InParameters.SpawnInstance_();
      FInParams.hDefKey:=HKEY_LOCAL_MACHINE;
      FInParams.sSubKeyName:='SYSTEM\CurrentControlSet';
      FInParams.uRequired:=KEY_QUERY_VALUE;
    
      FOutParams    := FWMIService.ExecMethod('StdRegProv', 'CheckAccess', FInParams);
      Writeln(Format('bGranted              %s',[FOutParams.bGranted]));
      Writeln(Format('ReturnValue           %s',[FOutParams.ReturnValue]));
    end;
    

    reading a string value

    // The GetStringValue method returns the data value for a named value whose data 
    // type is REG_SZ. 
    procedure  Invoke_StdRegProv_GetStringValue;
    const
      Server = '192.168.52.128';
      User   = 'Administrator';
      Pass   = 'password';
    var
      FSWbemLocator   : OLEVariant;
      FWMIService     : OLEVariant;
      FWbemObjectSet  : OLEVariant;
      FInParams       : OLEVariant;
      FOutParams      : OLEVariant;
    begin
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      //http://msdn.microsoft.com/en-us/library/aa393664%28v=vs.85%29.aspx
      //StdRegProv is preinstalled in the WMI namespaces root\default and root\cimv2.
      //Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0, and Windows Me/98/95:  StdRegProv is available only in root\default namespace.
      FWMIService   := FSWbemLocator.ConnectServer(Server, 'root\default', User, Pass);
      //For Windows Vista or Windows 7 you must use the  root\CIMV2 namespace
      //FWMIService   := FSWbemLocator.ConnectServer(Server, 'root\CIMV2', User, Pass);
      FWbemObjectSet:= FWMIService.Get('StdRegProv');
      FInParams     := FWbemObjectSet.Methods_.Item('GetStringValue').InParameters.SpawnInstance_();
      FInParams.hDefKey:=HKEY_LOCAL_MACHINE;
      FInParams.sSubKeyName:='SOFTWARE\Borland\Delphi\5.0';
      FInParams.sValueName:='App';
    
      FOutParams    := FWMIService.ExecMethod('StdRegProv', 'GetStringValue', FInParams);
      Writeln(Format('sValue                %s',[FOutParams.sValue]));
      Writeln(Format('ReturnValue           %s',[FOutParams.ReturnValue]));
    end;
    

    writing a string value

    // The SetStringValue method sets the data value for a named value whose data type 
    // is REG_SZ.
    procedure  Invoke_StdRegProv_SetStringValue;
    const
      Server = '192.168.52.128';
      User   = 'Administrator';
      Pass   = 'password';
    var
      FSWbemLocator   : OLEVariant;
      FWMIService     : OLEVariant;
      FWbemObjectSet  : OLEVariant;
      FInParams       : OLEVariant;
      FOutParams      : OLEVariant;
    begin
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      FWMIService   := FSWbemLocator.ConnectServer(Server, 'root\default', User, Pass);
      FWbemObjectSet:= FWMIService.Get('StdRegProv');
      FInParams     := FWbemObjectSet.Methods_.Item('SetStringValue').InParameters.SpawnInstance_();
      FInParams.hDefKey:=HKEY_LOCAL_MACHINE;
      FInParams.sSubKeyName:='SOFTWARE\Borland\Delphi\5.0';
      FInParams.sValueName:='Dummy';
      FInParams.sValue:='ADummyValue';
    
      FOutParams    := FWMIService.ExecMethod('StdRegProv', 'SetStringValue', FInParams);
      Writeln(Format('ReturnValue           %s',[FOutParams.ReturnValue]));
    end;
    

    For more options you must check the documentation about this class.

    I hope this help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Delphi TApplication.OnException Event to catch unhandled exceptions This works well but
Using Delphi, how do I access the equivalent of .NET's System.Environment.SpecialFolder.LocalApplicationData variable (which works
I'm using Delphi 7 Personal. To access MySQL database I'm using libmysql.dll + very
I am using Delphi 2009 which has the FastMM4 memory manager built into it.
I am using Delphi and trying to read from a bar code scanner over
Using Delphi 2007 I can write the following code: interface TTestType = (ttTest1, ttTest2);
Using Delphi 2010, let's say I've got a class declared like this: TMyList =
im working on application using delphi 7 , and i just came across this
Using Delphi XE. When trying to access a Delphi interface object from a DLL,
I'm using Delphi 2007 and I have this case: { CommonUnit.pas } type //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.