1. Home
  2. Computing & Technology
  3. Delphi Programming

Using the RunOnce Registry Key

By Zarko Gajic, About.com

Under Win32, unless you are running from a removable drive, you cannot delete a running executable. You can have Windows delete the executable the next time Windows is run by adding an entry to the RunOnce key in the Window registry under:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce

You can name the key anything you like, and specify a command line to another executable or to a dos command made passed to command.com

~~~~~~~~~~~~~~~~~~~~~~~~~
uses Registry;

procedure TForm1.Button1Click(Sender: TObject) ;
var reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.LazyWrite := False;
reg.OpenKey(
  'Software\Microsoft\Windows\
  CurrentVersion\RunOnce',
  False) ;
reg.WriteString('Delete Me!',
  'command.com /c del Dummy.txt') ;
reg.CloseKey;
reg.free;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Select a block of code by column
« Convert the First Character in an Edit Box to Uppercase

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 1999 Delphi Tips
  7. Using the RunOnce Registry Key

©2009 About.com, a part of The New York Times Company.

All rights reserved.