本文整理自网络,侵删。
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);beginCreateAutoRun(); //调用演示end;
相关阅读 >>
Delphi d10.x 安卓app开发中按返回键后程序不退出程序的方法
Delphi 查看字符串在不同编码(ascii、unicode、utf7、utf8、default、bigendianunicode)下的 hex
Delphi 2009 新增单元 character isletter、isupper、islower、isdigit、isnumber
更多相关阅读请进入《Delphi》频道 >>