Delphi 设置系统启动文件夹自身开机自动运行


本文整理自网络,侵删。

 

 uses  ShlObj, ShellAPI,System.IniFiles, System.UITypes;


 function GetAutoRunFilePath(): String;
var
  fileName, pathStartUp: String;
  path: array [0 .. 255] of Char;
begin
  fileName := Application.title + '.url'//url
  if SHGetSpecialFolderPath(0, @path[0], CSIDL_STARTUP, true) then
    pathStartUp := String(path);

  Result := pathStartUp + PathDelim + fileName;
end;

 procedure CreateAutoRun();
const
  FileProtocol = 'file:///';
var
  fileName: String;
  pathExe, pathUrl, pathAutoRun: String;
begin
  fileName := Application.title + '.url'; //url
  pathUrl := application.Exename;
  pathExe := ParamStr(0);

  pathAutoRun := GetAutoRunFilePath();

  with TIniFile.Create(pathAutoRun) do
    try
      WriteString('InternetShortcut', 'URL', FileProtocol + pathExe);
      WriteString('InternetShortcut', 'IconIndex', '0');
      WriteString('InternetShortcut', 'IconFile', pathExe);
    finally
      DisposeOf();
    end;

end;



procedure TForm1.FormCreate(Sender: TObject);
begin
CreateAutoRun();  //调用演示
end;

相关阅读 >>

Delphi webbrowser 加载html成web

Delphi 的内存操作函数(4): 清空与填充内存

Delphi数据库实现从最后一条记录向上查询至首记录

Delphi中adoquery执行错误的捕捉

Delphi 多种方法查找窗口句柄

Delphi 判断奇数偶数

Delphi 获取系统托盘程序列表

Delphi文件捆绑器

Delphi中ocx的动态注册方法

Delphi获取android上的imei

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...