Delphi 设置启动项

 

uses
  Registry;


procedure TForm1.Button1Click(Sender: TObject);
const
  sKey_MACHINE: array[0..7] of string =
  ('SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\Userinit',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\Setup',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx',
    'SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
    );

  sKey_USER: array[0..6] of string =
  ('Software\Microsoft\WindowsNT\CurrentVersion\Windows\load',
    'Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run',
    'Software\Microsoft\Windows\CurrentVersion\RunServicesOnce',
    'Software\Microsoft\Windows\CurrentVersion\RunServices',
    'Software\Microsoft\Windows\CurrentVersion\RunOnce\Setup',
    'Software\Microsoft\Windows\CurrentVersion\RunOnce',
    'Software\Microsoft\Windows\CurrentVersion\Run'
    );

var
  regTemp: TRegistry;
  slTemp, slResult: TStringList;
  iNum: Integer;
begin
  //清空Memo
  mmoResult.Clear;
  slTemp := TStringList.Create;
  slResult := TStringList.Create;
  regTemp := TRegistry.Create;
  //循环查找启动项
  regTemp.RootKey := HKEY_CURRENT_USER;
  for iNum := 0 to 6 do
  begin
    regTemp.OpenKey(sKey_USER[iNum], False);
    regTemp.GetValueNames(slTemp);
    slResult.AddStrings(slTemp);
    regTemp.CloseKey;
  end;
  //循环查找启动项
  regTemp.RootKey := HKEY_LOCAL_MACHINE;
  for iNum := 0 to 7 do
  begin
    regTemp.OpenKey(sKey_MACHINE[iNum], False);
    regTemp.GetValueNames(slTemp);
    slResult.AddStrings(slTemp);
    regTemp.CloseKey;
  end;

  //在Memo控件显示结果
  mmoResult.Lines.AddStrings(slResult);
  //释放regTemp
  regTemp.Free;
end;


 

你可能感兴趣的:(Delphi)