How to create an auto startup c++ program

依然范特西╮ 提交于 2019-11-30 17:38:45

Startup folder is clean enough.

Gives the user the possibility to remove it if needed.

There are many ways to autostart an application, but the easiest, most common and IMO best are:

  1. Put a shortcut in the autostart folder
  2. Add an autostart entry to the registry (Software\Microsoft\Windows\CurrentVersion\Run)

The end result is the same for both. I believe the registry way is executed earlier in the logon process than the startup way, but I am not certain. It does not make any difference for most cases anyway. I prefer the registry, but that is personal taste. You can create and delete the registry key or the shortcut programatically in your app.

With both options you can use either one setting for all users (All User startup folder, or under HKLM key in the registry) or user specific (user startup folder or under HKCR key).

In general it is better to use the per user options, because you can be certain to have writing privileges in those areas; and every user on the computer can have his/her own setting.

MSalters

Depending on whether you're executing an all-user or per-user install, put it in the Startup folder for All Users or the per-user Startup folder. The Startup folder you see in the menu is the merger of both, but non-admin users cannot remove the entries coming from the All-user part.

You actually don't have to do anything for this, though. Users can copy your normal shortcut to the Startup menu themselves. Hence, any program can be an auto-startup program. Doesn't need to be C++ at all.

You can register it as a windows service.You can use "Qt Solutions" for easily making an application as windows service.

ENDLESS

With this code you can do it

procedure TForm1.Button1Click(Sender: TObject);
var
   Reg:TRegistry;
begin
   Reg := TRegistry.Create;
   try
      Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run',True);
      Reg.WriteString('Program name',ParamStr(0));
   finally
     Reg.Free;
   end;

end;

or this:

using Microsoft.Win32;
private void AddStartUpKey(string _name, string  _path) {
     RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Micros  oft\Windows\CurrentVersion\Run", true);
     key.SetValue(_name, _path);
}
private void RemoveStartUpKey(string _name) {
     RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Micros  oft\Windows\CurrentVersion\Run", true);
     key.DeleteValue(_name, false);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!