Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

Update Registry Remotely LAN (URGENT)

Hi there,

I'm giving all my points for this one.
I work as a system admin and i need to modify/create, the registry on other PC's in the LAN.
I created some .reg files and tried to get my program to read the information and execute it on a remote pc, but it doesn't work, by the way it's XP Pro (No Service pack 2 installed, so it's not the firewall or nothing and i have admin previleges over the workstations on the LAN)

Anyway, i really need to do this, below is the code i've been testing but doesn't work :o/
Please help

Thank you!

procedure TForm1.Button1Click(Sender: TObject);
Var Reg: TRegistry;
begin
Reg := TRegistry.Create;
With Reg do
Begin
RootKey := HKEY_CURRENT_USER;
RegistryConnect('\\'+edit1.Text);
OpenKey ('\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3', TRUE);
WriteInteger('1803', 3);
CloseKey;
Free;
 
end;

end;

Hope you can help on this.


SFern.
0
sfern
Asked:
sfern
  • 16
  • 15
  • 2
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
The problem is the rootkey.
From delphi help:
Note:      Before calling RegistryConnect, an application must set the RootKey property for its registry object to HKEY_USERS or HKEY_LOCAL_MACHINE.
F68 ;-)
0
 
geobulCommented:
Hi,

HKEY_CLASSES_ROOT or HKEY_CURRENT_USER cannot be opened remotely. Only HKEY_LOCAL_MACHINE HKEY_USERS can be used.

Regards, Geo
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
What i mean is that you can access only those 2 rootkeys, HKEY_USERS or HKEY_LOCAL_MACHINE, but you're opening a key on HKEY_CURRENT_USER that can't be opend via LAN
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sfernAuthor Commented:
I've changed it to HKEY_LOCAL_MACHINE, but i get an error saying:

FAILED TO SET DATA FOR '1803'
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
i guess you have to use writebinarydata to store that value
0
 
sfernAuthor Commented:
Can you be more specific please?

Example?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
sorry, i went to see that regkey and found that it's DWORD type, so writeinteger should work fine....are you sure about the permissions/priviledges?
0
 
sfernAuthor Commented:
I Logged in as administrator and tried it, i didn't get the error anymore but it didn't change the setting...strange :o(
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Are you sure that the remote machine is UP? Maybe it's in standby mode....
0
 
sfernAuthor Commented:
Hmmmm

I've checked the Reg value and YES it has been changed to '3' which means that the user is not supposed to be able to download anything but he can.

Could it be that this reg change only works on HKEY_CURRENT_USER?

0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
You're right, i've the same result, but found that it works in HKEY_USERS
0
 
sfernAuthor Commented:
I changed it to HKEY_USERS and i'm getting the FAILED TO SET DATA FOR '1803' error again :o/
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
also note that IE reads the settings on run, so the chage have effect just on a new browser session.
I've tested it using HKEY_USERS and setting the value on all subkeys....  
0
 
sfernAuthor Commented:
Under HKEY_USERS the path is different, so i changed it to:

HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3

I now get the error: FAILED TO SET DATA FOR '1803'

:o(
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
mmm...
1st: under .DEFAULT don't works (as under HKLM)
2nd: it must be changed under the users profile (like HKEY_USERS\S-1-5-21-861567501-839522115-1060284298-1000) but you must have the right priviledges...
You said that it worked after logged in as admin....this means that the current user profile should let you change the value....
So you could do a loop for all the subK (s-1-5....) and change the value in a try/except (maybe writing a log error file in the except statment to see what happen)....
When you'll write in the current profile you should be able to set the new data, due to right priviledges....
0
 
sfernAuthor Commented:
And Yes, i'm opening each time on a new browser.
0
 
sfernAuthor Commented:
But Administrator account has TOP Priviladges doesn't it?

Sorry, but i don't know what you mean in your 2nd point, can you be more specific please?

Thanks

SFern.
0
 
sfernAuthor Commented:
I NEED HELP PLEASE :o(
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Sorry, i'm at work now and i don't have so many time to write an example....
BTW you're right about the admin level....

i was meaning that you could try to loop into HKUs and set that value in all SID's keys with a try/except...

maybe i'll have more time this evening at home (here's 1.00 PM now)...
0
 
sfernAuthor Commented:
Thanks ...Here 1.00PM Also... :o)
0
 
geobulCommented:
Hi,

F68 means something like:

uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
var
  sl: TStringList;
  i: integer;
begin
  with TRegistry.Create do begin
    sl := TStringList.Create;
    try
      RootKey := HKEY_USERS;
      RegistryConnect('\\'+edit1.Text);
      OpenKey('', false);
      CloseKey;
      GetKeyNames(sl);
      for i := 0 to sl.Count - 1 do begin
        if OpenKey('\' + sl[i] + '\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3', true) then begin
          WriteInteger('1803', 3);
          CloseKey;
        end;
      end;
    finally
      sl.Free;
      Free;
    end;
  end;
end;

Regards, Geo
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Hi geo :)
Yes, i was working on something like this (found some time) but as you've already done it i can escape it now :)

BTW sfern, just another thing: you must be sure that the remote registry service is installed on the client....
0
 
sfernAuthor Commented:
I'm still able to Download and the value is now changing :o/   Strange. :o(
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
also re-opening the browser after the change?
0
 
sfernAuthor Commented:
Yes, even trying on my local pc...  :o(   Seems to just want HK_CURRENT_USER :o(
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
if i change it on my local PC in HKEY_USERS (under my SID) it works
0
 
sfernAuthor Commented:
The problem is that i need to do this to a network of computers, but want to do it remotely.
I would then have to get the SID of all workstations?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Using the loop you don't need to get the sid....
By the way try this one on your own PC and see the effect:

function SidToStr(Username: String): string;
var
    i, cSid, cRefDomainName, peUse, NumSubAuthority: Cardinal;
    SidAuthority: Double;
    CurrentUserName: string;
    pSID, RefDomain: array[1..255] of Byte;
    SidIDAuthority: TSIDIdentifierAuthority;
    sSid: string;
begin
    cSid := SizeOf(pSid);
    cRefDomainName := SizeOf(RefDomain);
    FillChar(pSID, SizeOf(pSID), 0);
    FillChar(RefDomain, SizeOf(RefDomain), 0);
    CurrentUserName := UserName;
    LookupAccountName(nil, PChar(CurrentUserName), @pSID, cSid, @RefDomain, cRefDomainName, peUse);

    // Initial SID string.
    // I'm not sure how to get revision level, but
    // all appear to be 1.  ???
    sSid := 'S-1-';

    // Get the SID authority.
    SidIDAuthority := GetSidIdentifierAuthority(@pSid)^;
    SidAuthority := 0;
    for i := 0 to 5 do
        SidAuthority := SidAuthority + (SidIDAuthority.Value[i] shl (8 * (5 - i)));
    sSid := sSid + FloatToStr(SidAuthority) + '-';

    // Get the SID sub-authoritiy(s).
    NumSubAuthority := Integer(GetSidSubAuthorityCount(@pSid)^);
    for i := 0 to NumSubAuthority - 1 do
        sSid := sSid + IntToStr(GetSidSubAuthority(@pSid, i)^) + '-';

    // Remove the last "-" from the SID, and return it.
    sSid := Copy(sSid, 1, Length(sSid) - 1);
    Result := sSid;
end;


procedure TForm1.Button1Click(Sender: TObject);
Var Reg: TRegistry;
begin
Reg := TRegistry.Create;
With Reg do
Begin
RootKey := HKEY_USERS;
RegistryConnect('\\'+Edit1.Text); //write in edit1.text the name of your machine
OpenKey ('\'+SidToStr({type here your UserName})+'\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3', TRUE);
WriteInteger('1803', 3);
CloseKey;
Free;

end;


end;
0
 
sfernAuthor Commented:
I'll try your code now.

BTW: I created a .REG file that contains the follwing code and works fine:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3]
"1803"=dword:00000003

If i couldn't get it to work, if there a way of just running the file remotely?

0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
--just running the file remotely?
for this there's a good Command Prompt utility
http://www.sysinternals.com/ntw2k/freeware/psexec.shtml
you could execute it from your delphi app using winexec or shellexecute passing to it the parameters for the machine and the file to execute....
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
for example: create a little exe that writes the value in HKCU in a local machine registry (let's say MyRegTool.exe)

then  another little app with a
Winexec(Pchar('psexec \\'+edit1.text+' -c MyRegTool.exe',0)...

MyRegTool will be copied and executed on the remote machine

what about this idea?

0
 
sfernAuthor Commented:
It's Finally worked :o)

Thanks a million !!!!


SFern.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Glad to have helped you :)
BTW as the suggestions were various and different, wich was the working one?

F68 ;)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 16
  • 15
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now