Hello!

Here I dug out the site, what path to the registry you need to self-delete the program: " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce "

The entries in this section indicate the names of the files that are to be executed once during system boot. To remove a program, you just need to add an entry with the name of the file that will delete it or with the command del "file name". "

But I can not understand what to do in Delphi. Here is what he wrote:

 reg:=TRegistry.Create; reg.RootKey:=HKEY_LOCAL_MACHINE; try reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce',true); reg.WriteString('del','del "C:\...\Project2.exe"'); reg.CloseKey; reg.Free; except end; 

    2 answers 2

    1. Try slashes Duplicate: instead of \ write \\, for example so

      reg.WriteString ('del', 'del' + StringReplace ('"C: \ ... \ Project2.exe"', '\', '\\', [rfReplaceAll]);

    2. Remove try except end and see what error gives - maybe you do not have rights to write to this thread.

    3. What is recorded in the registry look.

    4. Try writing the command to the registry manually and check if it works on reboot - this key can be ignored if this is specified in the security policy.

    5. Try writing such a command to the registry.

      cmd / C del / F / Q "C: \ RHDSetup.log"

    • ERROR: Failed to set data for 'del' - NIXON_NB
    • Your code works without problems for me, maybe you do not have rights to write to this registry branch. Give yourself rights and try again. <br> Yes, only the path must be specified correctly, of course, and yes, a registry entry appears. <br> Some antiviruses may block writing to this thread, such as viral activity :) - toxicdream
    • Do I have Windows 7 does this affect this ?! Damn lemit ended! By the way, you need to create your own portmeter, or write one where the Name: "Default" is NIXON_NB
    • Try to execute this command manually from the console, and check that it works correctly <br> del / F / Q "C: \ realtek.log" <br> / F - delete even if the file is read-only <br> / Q - do not delete I ask for confirmation <br> Version of Windows, it seems, should not affect the work of the script - toxicdream
    • By the way, you need to create your own parameter (and which one?) Or write one in where the Name: “Default” is NIXON_NB

    For self-deletion, it is best to use a bat file.

     :1 del /F /Q "C:\prog.exe" || goto :1 del /F /Q "C:\delete_prog.bat" 

    Generate and run it directly from the program. The 2nd line will try to remove prog.exe while the running process of the program does not release it. After successful removal of the program, the 3rd line will delete the bat file itself.

    UPD: For the deletion process to work in the background without the console window in the taskbar, you need to run it through ShellExecute(0, 'Open', 'C:\delete_prog.bat', nil, nil, SW_HIDE)