Создание ярлыков объектов на рабочем столе, старт меню, панели быстрого запуска
Создание ярлыков объектов на рабочем столе, старт меню, панели быстрого запуска
Создание ярлыков объектов на рабочем столе, старт меню, панели быстрого запуска uses registry, activex, comobj, shlobj; type shortcuttype = (_desktop, _quicklaunch, _sendto, _startmenu, _otherfolder); function createshortcut(sourcefilename: string; // the file the shortcut points to location: shortcuttype; // shortcut location subfolder, // subfolder of location workingdir, // working directory property of the shortcut parameters, description: string): // description property of the shortcut string; const shell_folders_root = 'softwaremicrosoftwindowscurrentversionexplorer'; quick_launch_root = 'softwaremicrosoftwindowscurrentversiongrpconv'; var myobject: iunknown; myslink: ishelllink; mypfile: ipersistfile; directory, linkname: string; wfilename: widestring; reg: treginifile; begin myobject := createcomobject(clsid_shelllink); myslink := myobject as ishelllink; mypfile := myobject as ipersistfile; myslink.setpath(pchar(sourcefilename)); myslink.setarguments(pchar(parameters)); myslink.setdescription(pchar(description)); linkname := changefileext(sourcefilename, '.lnk'); linkname := extractfilename(linkname); // quicklauch if location = _quicklaunch then begin reg := treginifile.create(quick_launch_root); try directory := reg.readstring('mapgroups', 'quick launch', ''); finally reg.free; end; end else // other locations begin reg := treginifile.create(shell_folders_root); try case location of _otherfolder : directory := subfolder; _desktop : directory := reg.readstring('shell folders', 'desktop', ''); _startmenu : directory := reg.readstring('shell folders', 'start menu', ''); _sendto : directory := reg.readstring('shell folders', 'sendto', ''); end; finally reg.free; end; end; if directory <> '' then begin if (subfolder <> '') and (location <> _otherfolder) then wfilename := directory + '' + subfolder + '' + linkname else wfilename := directory + '' + linkname; if workingdir = '' then myslink.setworkingdirectory(pchar(extractfilepath(sourcefilename))) else myslink.setworkingdirectory(pchar(workingdir)); mypfile.save(pwchar(wfilename), false); result := wfilename; end; end; function getprogramdir: string; var reg: tregistry; begin reg := tregistry.create; try reg.rootkey := hkey_current_user; reg.openkey('softwaremicrosoftwindowscurrentversionexplorershell folders', false); result := reg.readstring('programs'); reg.closekey; finally reg.free; end; end; // some examples: procedure tform1.button1click(sender: tobject); const progr = 'c:yourprogram.exe'; var respath: string; begin //create a shortcut in the quckick launch toolbar createshortcut(progr, _quicklaunch, '','','','description'); //create a shortcut on the desktop createshortcut(progr, _desktop, '','','','description'); //create a shortcut in the startmenu /"programs"-folder respath := createshortcut(progr, _otherfolder, getprogramdir,'','','description'); if respath <> '' then begin showmessage('shortcut successfully created in: ' + respath); end; end;