Re: [Lazarus] Remote Registry...
On Fri, 23 Aug 2013, Flávio Etrusco wrote: On Thu, Aug 22, 2013 at 9:55 PM, waldo kitty wkitt...@windstream.net wrote: On 8/22/2013 16:46, Liyuan Garcia Caballero wrote: Hi guys, I need access to remote registry of Microsoft Window and get a data, it's posible with Pascal? of course it is possible... the question is how are you expecting to be able to perform this task... Somebody can share one code? no but possibly an idea or two... write a remote server that accesses the registry for whatever you want... then talk to it via a local client... in reality, it should be no different than using ssh or rdp into the remote host and starting the remote machine's regedit or similar... capturing that information and feeding it back across the link... NOTE: i use the term server above because you are wanting to connect to a remote system and pull data from it... in the most general terms, that makes it a server... the connecting package on the local side is then considered a client... I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx Currently this is not supported by FPC. What needs to be done is implement function TRegistry.RegistryConnect(const UNCName: string): Boolean; begin Result := False; end; in packages/fcl-registry/src. The function indicated by Flavio must be used for this. So I'd guess that would be something like: function TRegistry.RegistryConnect(const UNCName: string): Boolean; Var Res : HKey; begin Result := RegConnectRegistryA(PAnsiChar(UNCName),FRootKey,@HKey); if Result then FCurentKey:=Res; end; Michael.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
Am 23.08.2013 09:50, schrieb Michael Van Canneyt: On Fri, 23 Aug 2013, Flávio Etrusco wrote: On Thu, Aug 22, 2013 at 9:55 PM, waldo kitty wkitt...@windstream.net wrote: On 8/22/2013 16:46, Liyuan Garcia Caballero wrote: Hi guys, I need access to remote registry of Microsoft Window and get a data, it's posible with Pascal? of course it is possible... the question is how are you expecting to be able to perform this task... Somebody can share one code? no but possibly an idea or two... write a remote server that accesses the registry for whatever you want... then talk to it via a local client... in reality, it should be no different than using ssh or rdp into the remote host and starting the remote machine's regedit or similar... capturing that information and feeding it back across the link... NOTE: i use the term server above because you are wanting to connect to a remote system and pull data from it... in the most general terms, that makes it a server... the connecting package on the local side is then considered a client... I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx Currently this is not supported by FPC. What needs to be done is implement function TRegistry.RegistryConnect(const UNCName: string): Boolean; begin Result := False; end; in packages/fcl-registry/src. The function indicated by Flavio must be used for this. So I'd guess that would be something like: function TRegistry.RegistryConnect(const UNCName: string): Boolean; Var Res : HKey; begin Result := RegConnectRegistryA(PAnsiChar(UNCName),FRootKey,@HKey); if Result then FCurentKey:=Res; end; Not entirely. According to the Delphi documentation RootKey needs to be set instead of CurrentKey and also the key must be closed in the end. I've already done the implementation and I'm currently testing it. As a workaround for older FPC versions simply set RootKey to the value returned by RegConnectRegistry. Note: The login stuff mentioned on the MSDN page needs to be done nevertheless. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
Am 23.08.2013 10:05, schrieb Sven Barth: Am 23.08.2013 09:50, schrieb Michael Van Canneyt: On Fri, 23 Aug 2013, Flávio Etrusco wrote: On Thu, Aug 22, 2013 at 9:55 PM, waldo kitty wkitt...@windstream.net wrote: On 8/22/2013 16:46, Liyuan Garcia Caballero wrote: Hi guys, I need access to remote registry of Microsoft Window and get a data, it's posible with Pascal? of course it is possible... the question is how are you expecting to be able to perform this task... Somebody can share one code? no but possibly an idea or two... write a remote server that accesses the registry for whatever you want... then talk to it via a local client... in reality, it should be no different than using ssh or rdp into the remote host and starting the remote machine's regedit or similar... capturing that information and feeding it back across the link... NOTE: i use the term server above because you are wanting to connect to a remote system and pull data from it... in the most general terms, that makes it a server... the connecting package on the local side is then considered a client... I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx Currently this is not supported by FPC. What needs to be done is implement function TRegistry.RegistryConnect(const UNCName: string): Boolean; begin Result := False; end; in packages/fcl-registry/src. The function indicated by Flavio must be used for this. So I'd guess that would be something like: function TRegistry.RegistryConnect(const UNCName: string): Boolean; Var Res : HKey; begin Result := RegConnectRegistryA(PAnsiChar(UNCName),FRootKey,@HKey); if Result then FCurentKey:=Res; end; Not entirely. According to the Delphi documentation RootKey needs to be set instead of CurrentKey and also the key must be closed in the end. I've already done the implementation and I'm currently testing it. As a workaround for older FPC versions simply set RootKey to the value returned by RegConnectRegistry. Note: The login stuff mentioned on the MSDN page needs to be done nevertheless. Implemented in FPC revision 25332. Attached is an example program that shows how to remotely connect to another machine (this can also be used for using RegConnectRegistry directly in case of FPC 2.6.2 and older). The machine name is given as UNC name as first argument (e.g. \\SomeComputer) and the username as second argument. The password will be queried on the command line by Windows. If the connection is successful the keys of HKEY_USERS of the remote machine will be enumerated. Tested on a Windows 7 machine connecting to another Windows 7 machine. Note: The remote registry service must run on the destination machine. Regards, Sven program remotereg; {$mode objfpc}{$H+} {$apptype console} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes { you can add units after this }, sysutils, windows, registry, JwaWinNetWk, JwaWinType; var reg: TRegistry; machine, username, s: String; res: NETRESOURCEA; err: DWORD; sl: TStringList; begin if ParamCount 0 then machine := ParamStr(1) else machine := ''; if ParamCount 1 then username := ParamStr(2) else username := ''; if (machine '') and (username '') then begin Writeln('Connecting to ', machine, ' as ', username); FillChar(res, SizeOf(res), 0); res.dwType := RESOURCETYPE_ANY; res.lpRemoteName := PChar(Format('%s\IPC$', [machine])); err := WNetAddConnection2A(res, Nil, PChar(username), CONNECT_TEMPORARY or CONNECT_INTERACTIVE or CONNECT_COMMANDLINE); if (err NO_ERROR) and (err ERROR_SESSION_CREDENTIAL_CONFLICT) then begin Writeln('Error connecting to remote machine ''', machine, ''': ', SysErrorMessage(err), ' (', err, ')'); Readln; Exit; end; end; reg := TRegistry.Create(KEY_ENUMERATE_SUB_KEYS); try reg.RootKey := HKEY_USERS; if not reg.RegistryConnect(machine) then begin Writeln('Error connecting to remote registry'); Exit; end; reg.OpenKeyReadOnly('\'); sl := TStringList.Create; try reg.GetKeyNames(sl); Writeln(sl.Count, ' keys found'); for s in sl do Writeln(#9, s); finally sl.Free; end; reg.CloseKey; finally reg.Free; end; Writeln('Done'); Readln; end. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
Not entirely. According to the Delphi documentation RootKey needs to be set instead of CurrentKey and also the key must be closed in the end. I've already done the implementation and I'm currently testing it. As a workaround for older FPC versions simply set RootKey to the value returned by RegConnectRegistry. Note: The login stuff mentioned on the MSDN page needs to be done nevertheless. Implemented in FPC revision 25332. Attached is an example program that shows how to remotely connect to another machine (this can also be used for using RegConnectRegistry directly in case of FPC 2.6.2 and older). The machine name is given as UNC name as first argument (e.g. \\SomeComputer) and the username as second argument. The password will be queried on the command line by Windows. If the connection is successful the keys of HKEY_USERS of the remote machine will be enumerated. Tested on a Windows 7 machine connecting to another Windows 7 machine. Note: The remote registry service must run on the destination machine. Maybe commit the example in fcl-registry/examples ? Michael. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
Am 23.08.2013 10:37, schrieb Michael Van Canneyt: Not entirely. According to the Delphi documentation RootKey needs to be set instead of CurrentKey and also the key must be closed in the end. I've already done the implementation and I'm currently testing it. As a workaround for older FPC versions simply set RootKey to the value returned by RegConnectRegistry. Note: The login stuff mentioned on the MSDN page needs to be done nevertheless. Implemented in FPC revision 25332. Attached is an example program that shows how to remotely connect to another machine (this can also be used for using RegConnectRegistry directly in case of FPC 2.6.2 and older). The machine name is given as UNC name as first argument (e.g. \\SomeComputer) and the username as second argument. The password will be queried on the command line by Windows. If the connection is successful the keys of HKEY_USERS of the remote machine will be enumerated. Tested on a Windows 7 machine connecting to another Windows 7 machine. Note: The remote registry service must run on the destination machine. Maybe commit the example in fcl-registry/examples ? Done in 25334. Including a few comments on what's happening. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
On 8/22/2013 23:08, Flávio Etrusco wrote: I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx interesting... you'd think that people would mention these things and give links as above if it is what they are actually after... thanks for the pointer and to michael for the additional information... and definitely thanks to sven for the implementation... now we wait to see if the OP can update to the latest FPC SVN, as indicated by sven, to gain access to it... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
On 23.08.2013 15:46, waldo kitty wrote: On 8/22/2013 23:08, Flávio Etrusco wrote: I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx interesting... you'd think that people would mention these things and give links as above if it is what they are actually after... thanks for the pointer and to michael for the additional information... and definitely thanks to sven for the implementation... now we wait to see if the OP can update to the latest FPC SVN, as indicated by sven, to gain access to it... He can also use the functionality in 2.6.x, 2.7.1 just wraps the necessary house keeping. For this he can open the remote registry with RegConnectRegistry and pass resulting HKEY handle to the Rootkey property of a TRegistry instance. Afterwards he can work normally with TRegistry. At the end he needs to close the Rootkey using RegCloseKey. This is basically what TRegistry now does in 2.7.1 as well. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
On 8/23/2013 13:25, Sven Barth wrote: On 23.08.2013 15:46, waldo kitty wrote: On 8/22/2013 23:08, Flávio Etrusco wrote: I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx interesting... you'd think that people would mention these things and give links as above if it is what they are actually after... thanks for the pointer and to michael for the additional information... and definitely thanks to sven for the implementation... now we wait to see if the OP can update to the latest FPC SVN, as indicated by sven, to gain access to it... He can also use the functionality in 2.6.x, 2.7.1 just wraps the necessary house keeping. right but it has to be specifically added, correct? it has not (yet) been added other than in FPC trunk? i did see it come in here when i svn upped my FPC and lazarus a few hours ago ;) For this he can open the remote registry with RegConnectRegistry and pass resulting HKEY handle to the Rootkey property of a TRegistry instance. Afterwards he can work normally with TRegistry. At the end he needs to close the Rootkey using RegCloseKey. This is basically what TRegistry now does in 2.7.1 as well. can i assume that RegCloseKey sends the possibly modified key back to the remote? i'm just asking to learn O:) -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
On 23.08.2013 19:51, waldo kitty wrote: On 8/23/2013 13:25, Sven Barth wrote: On 23.08.2013 15:46, waldo kitty wrote: On 8/22/2013 23:08, Flávio Etrusco wrote: I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx interesting... you'd think that people would mention these things and give links as above if it is what they are actually after... thanks for the pointer and to michael for the additional information... and definitely thanks to sven for the implementation... now we wait to see if the OP can update to the latest FPC SVN, as indicated by sven, to gain access to it... He can also use the functionality in 2.6.x, 2.7.1 just wraps the necessary house keeping. right but it has to be specifically added, correct? it has not (yet) been added other than in FPC trunk? i did see it come in here when i svn upped my FPC and lazarus a few hours ago ;) Code in trunk: === code begin === sl := Nil; reg := TRegistry.Create(KEY_READ); try reg.RootKey := HKEY_USERS; if not reg.ConnectRegistry('\\SomeMachine') then raise Exception.Create('Could not connect'); reg.OpenKeyReadOnly('\'); sl := TStringList.Create; reg.GetKeyNames(sl); for s in sl do Writeln(s); finally reg.Free; sl.Free; end; === code end === Equivalent code in 2.6.2 and earlier: === code begin === sl := Nil; reg := TRegistry.Create(KEY_READ); try if RegConnectRegistry('\\SomeMachine', HKEY_USERS, key) ERROR_SUCCESS then raise Exception.Create('Could not connect'); reg.RootKey := key; reg.OpenKeyReadOnly('\Software'); sl := TStringList.Create; reg.GetKeyNames(sl); for s in sl do Writeln(s); finally reg.Free; sl.Free; end; === code end === For this he can open the remote registry with RegConnectRegistry and pass resulting HKEY handle to the Rootkey property of a TRegistry instance. Afterwards he can work normally with TRegistry. At the end he needs to close the Rootkey using RegCloseKey. This is basically what TRegistry now does in 2.7.1 as well. can i assume that RegCloseKey sends the possibly modified key back to the remote? i'm just asking to learn O:) You are only opening either HKEY_USERS, HKEY_LOCAL_MACHINE or HKEY_PERFORMANCE_DATA using RegConnectRegistry/TRegistry.ConnectRegistry. All other subkeys are opened using the normal registry API (be it directly or through TRegistry) and Windows handles the rest. When exactly it sends the modifications to the remote machine is up to Windows. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Remote Registry...
Hi guys, I need access to remote registry of Microsoft Window and get a data, it's posible with Pascal? Somebody can share one code? Thank a lot -- Este mensaje ha sido analizado por MailScanner en busca de virus y otros contenidos peligrosos, y se considera que está limpio. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
On 8/22/2013 16:46, Liyuan Garcia Caballero wrote: Hi guys, I need access to remote registry of Microsoft Window and get a data, it's posible with Pascal? of course it is possible... the question is how are you expecting to be able to perform this task... Somebody can share one code? no but possibly an idea or two... write a remote server that accesses the registry for whatever you want... then talk to it via a local client... in reality, it should be no different than using ssh or rdp into the remote host and starting the remote machine's regedit or similar... capturing that information and feeding it back across the link... NOTE: i use the term server above because you are wanting to connect to a remote system and pull data from it... in the most general terms, that makes it a server... the connecting package on the local side is then considered a client... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Remote Registry...
On Thu, Aug 22, 2013 at 9:55 PM, waldo kitty wkitt...@windstream.net wrote: On 8/22/2013 16:46, Liyuan Garcia Caballero wrote: Hi guys, I need access to remote registry of Microsoft Window and get a data, it's posible with Pascal? of course it is possible... the question is how are you expecting to be able to perform this task... Somebody can share one code? no but possibly an idea or two... write a remote server that accesses the registry for whatever you want... then talk to it via a local client... in reality, it should be no different than using ssh or rdp into the remote host and starting the remote machine's regedit or similar... capturing that information and feeding it back across the link... NOTE: i use the term server above because you are wanting to connect to a remote system and pull data from it... in the most general terms, that makes it a server... the connecting package on the local side is then considered a client... I guess he means this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724840%28v=vs.85%29.aspx -Flávio -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus