Solved

Update Registry Remotely LAN (URGENT)

Posted on 2004-09-16
33
517 Views
Last Modified: 2010-05-18
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
Comment
Question by:sfern
  • 16
  • 15
  • 2
33 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12072618
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
 
LVL 17

Expert Comment

by:geobul
ID: 12072632
Hi,

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

Regards, Geo
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12072633
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
 

Author Comment

by:sfern
ID: 12072689
I've changed it to HKEY_LOCAL_MACHINE, but i get an error saying:

FAILED TO SET DATA FOR '1803'
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12072731
i guess you have to use writebinarydata to store that value
0
 

Author Comment

by:sfern
ID: 12072774
Can you be more specific please?

Example?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12072873
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
 

Author Comment

by:sfern
ID: 12072886
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12072904
Are you sure that the remote machine is UP? Maybe it's in standby mode....
0
 

Author Comment

by:sfern
ID: 12072905
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12072965
You're right, i've the same result, but found that it works in HKEY_USERS
0
 

Author Comment

by:sfern
ID: 12073026
I changed it to HKEY_USERS and i'm getting the FAILED TO SET DATA FOR '1803' error again :o/
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12073046
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
 

Author Comment

by:sfern
ID: 12073126
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12073169
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
 

Author Comment

by:sfern
ID: 12073173
And Yes, i'm opening each time on a new browser.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:sfern
ID: 12073183
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
 

Author Comment

by:sfern
ID: 12073439
I NEED HELP PLEASE :o(
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12073490
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
 

Author Comment

by:sfern
ID: 12073504
Thanks ...Here 1.00PM Also... :o)
0
 
LVL 17

Expert Comment

by:geobul
ID: 12074582
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12074636
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
 

Author Comment

by:sfern
ID: 12074885
I'm still able to Download and the value is now changing :o/   Strange. :o(
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12074902
also re-opening the browser after the change?
0
 

Author Comment

by:sfern
ID: 12074969
Yes, even trying on my local pc...  :o(   Seems to just want HK_CURRENT_USER :o(
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12075003
if i change it on my local PC in HKEY_USERS (under my SID) it works
0
 

Author Comment

by:sfern
ID: 12075056
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
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 365 total points
ID: 12075118
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
 

Author Comment

by:sfern
ID: 12075294
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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12075477
--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
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12075564
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
 

Author Comment

by:sfern
ID: 12077471
It's Finally worked :o)

Thanks a million !!!!


SFern.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12082004
Glad to have helped you :)
BTW as the suggestions were various and different, wich was the working one?

F68 ;)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now