为什么添加开机启动不成功,代码如下:-------------------------------------------------------------------------------
procedure TFrm_Main.FormCreate(Sender: TObject);
Var
Msg:Tmessage;
reg:TRegistry;
FileName, FilePath: string;
begin
  FileName := ExtractFileName(application.ExeName); //开机启动的执行程序名
  FilePath := application.ExeName;//完整路径
  Reg := Tregistry.Create;
  try
    Reg.Rootkey := HKEY_LOCAL_MACHINE;
    Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', true);
    Reg.WriteString(FileName, FilePath); //添加注册表项和键值
    Reg.CloseKey; //关闭注册表
  finally
    Reg.Free;
  end;
  WMDeviceChange(Msg);
  Application.ShowMainForm:=False;
end;-----------------------------------------------------------------------------
请教是哪里出错了?