Here is the code that does what you wanted. I have used it a long time ago and it is sitting in my helper units. Can't remember if I wrote it or reused it from somewhere else.
What it does it to search for Regedit's window, launch it if it is not running, and automate it by sending messages to simulate key presses for navigating the required key. Not a native solution as passing a command line param, but is working pretty well.
// Open Registry editor and go to the specified key
procedure JumpToRegKey(const aKey: string);
var
I, J: Integer;
hWin: HWND;
ExecInfo: TShellExecuteInfo;
begin
// Check if regedit is running and launch it if not
// All the code below depends on specific window titles and classes, so it will fail if MS changes the Regedit app
hWin := FindWindow(PChar('RegEdit_RegEdit'), nil);
if hWin = 0 then
begin
ZeroMemory(@ExecInfo, sizeof(ExecInfo));
with ExecInfo do
begin
cbSize := SizeOf(TShellExecuteInfo);
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpVerb := PChar('open');
lpFile := PChar('regedit.exe');
nShow := SW_SHOWMAXIMIZED;
end;
ShellExecuteEx(@ExecInfo);
WaitForInputIdle(ExecInfo.hProcess, 200);
hWin := FindWindow(PChar('RegEdit_RegEdit'), nil);
end;
if hWin <> 0 then
begin
ShowWindow(hWin, SW_SHOWMAXIMIZED);
hWin := FindWindowEx(hWin, 0, PChar('SysTreeView32'), nil);
SetForegroundWindow(hWin);
// Collapse the tree first by sending a large number of Left arrow keys
I := 30;
repeat
SendMessage(hWin, WM_KEYDOWN, VK_LEFT, 0);
Dec(I);
until I = 0;
Sleep(100);
SendMessage(hWin, WM_KEYDOWN, VK_RIGHT, 0);
Sleep(100);
I := 1;
J := Length(aKey);
repeat
if aKey[I] = '\' then
begin
SendMessage(hWin, WM_KEYDOWN, VK_RIGHT, 0);
Sleep(50);
end
else
SendMessage(hWin, WM_CHAR, Integer(aKey[I]), 0);
I := I + 1;
until I = J;
end;
end;
There is a limitation for the usage of this code, as kobik reminded. A non-elevated app can not send messages to an elevated one. Regedit is elevated, so the code can be used either if your app has elevated privileges, or if the UAC is turned off.
Otherwise it will launch the process(which will ask for approval) and find its window, but PostMessage will not work.