Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TRegistryIniFile and HKEY_LOCAL_MACHINE

462 views
Skip to first unread message

Paul Tugwell

unread,
Jul 2, 2008, 12:28:13 PM7/2/08
to
I want to create a system DSN entry for and ODBC driver in code. I have
found some code that creates the entry for me, but as a user DSN. It uses
TRegistryIniFile to create the entry, and this always seems to create a key
in HKEY_CURRENT_USER. Is there a way to use TRegistryIniFile to create a key
in HKEY_LOCAL_MACHINE? If so, how?


Paul Keating

unread,
Jul 2, 2008, 12:53:50 PM7/2/08
to
You may have to bite the bullet and recode against TRegistry.

It's not hard:

LocalMachine := TRegistry.Create(KEY_READ);
LocalMachine.RootKey := HKey_Local_Machine;
LocalMachine.OpenKey('Software\..\..\..',True);
LocalMachine.WriteString('myvalue');
LocalMachine.CloseKey();
LocalMachine.OpenKey('',False);


--

"Paul Tugwell" <pa...@guardbase.co.uk> wrote

Chris Rolliston

unread,
Jul 2, 2008, 1:27:01 PM7/2/08
to

Sure - immediately after creating the TRegistryIniFile instance, set
RegIniFile.RootKey, then reset the base path (as setting RootKey clears
it):

Settings := TRegistryIniFile.Create(MyRegPath);
try
Settings.RegIniFile.RootKey := HKEY_LOCAL_MACHINE;
Settings.RegIniFile.OpenKey(Settings.FileName, True);
//do stuff
finally
Settings.Free;
end;

Note you app will need to have administrator rights - Vista will
silently convert your WriteXXX calls to a 'VirtualStore' key somewhere
under HKEY_CURRENT_USER otherwise.

0 new messages