Here is what I came up with that works
You will need elevated privileges to run it.
procedure TForm1.setlockscreen(slockscreenPath: string);
var
reg: TRegistry;
begin
try
if (slockscreenPath = 'clear') then
begin
try
reg := TRegistry.Create(KEY_WRITE or KEY_WOW64_64KEY);
reg.Lazywrite := False;
reg.RootKey := hkey_local_machine;
if reg.OpenKey(
'SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background', True) then
begin
reg.Writeinteger('OEMBackground', StrToInt('$00000000'));
SysUtils.ExecuteProcess(UTF8ToSys('rundll32'),
(UTF8ToSys('"USER32.DLL,UpdatePerUserSystemParameters, 1, True"')), []);
exit;
end;
finally
reg.Free;
end;
end;
try
reg := TRegistry.Create(KEY_WRITE or KEY_WOW64_64KEY);
reg.Lazywrite := False;
reg.RootKey := hkey_local_machine;
if reg.OpenKey(
'SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background', True) then
begin
reg.Writeinteger('OEMBackground', StrToInt('$00000001'));
end;
if not (directoryexists(windowsfolder + '\SysNative\oobe\info\backgrounds')) then
createdir(windowsfolder + '\SysNative\oobe\info\backgrounds');
if (fileexists(windowsfolder +
'\SysNative\oobe\info\backgrounds\backgroundDefault.jpg')) then
begin
deletefile(windowsfolder +
'\SysNative\oobe\info\backgrounds\backgroundDefault.jpg');
end;
copyfile(slockscreenPath,
windowsfolder + '\SysNative\oobe\info\backgrounds\backgroundDefault.jpg');
SysUtils.ExecuteProcess(UTF8ToSys('rundll32'),
(UTF8ToSys('"USER32.DLL,UpdatePerUserSystemParameters, 1, True"')), []);
finally
reg.Free;
end;
except
on E: Exception do
DumpExceptionCallStack(E);
end;
end;