一个简单的问题(5分)

  • 主题发起人 主题发起人 king_213
  • 开始时间 开始时间
K

king_213

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在第一次运行程序后 自动在桌面上建立一个该程序的快捷方式???
 
帮顶,手动创建不更简单么?
 
在wise安装程序里有这个选项
 
或者用winrar做自解压包时也有这个项
 
只有一个可执行程序 还要打包吗
 
uses
comobj,activex,shlobj;


type //快捷方式位置
TLinkPlace=(lkDeskTop,//桌面
lkStartMenu,//开始菜单
lkProgram);//程序
var
LinkPlace:array [0..2] of integer=
(CSIDL_DESKTOPDIRECTORY,
CSIDL_STARTMENU,
CSIDL_PROGRAMS);

procedure CreateLink(LinkFile:WideString;LinkName:string;const Place:TLinkPlace);
var
lvs_FileName,lvs_StartupFilename:string;
lvo_Object:IUnknown;
lvo_SLink:IShellLink;
lvo_PFile:IPersistFile;
lvo_PIDL : PItemIDList;
lvs_StartupDirectory : array[0..MAX_PATH] of Char;
lvs_LinkFilename : WideString;
begin
lvs_StartupFilename := LinkFile ;
lvo_Object := CreateComObject(CLSID_ShellLink);
lvo_SLink := lvo_Object as IShellLink;
lvo_PFile := lvo_Object as IPersistFile;
lvo_SLink.SetPath(pChar(lvs_StartupFilename));
lvo_SLink.SetWorkingDirectory(PChar(ExtractFilePath(lvs_StartupFilename)));
SHGetSpecialFolderLocation(0, LinkPlace[Ord(Place)], lvo_PIDL);
SHGetPathFromIDList(lvo_PIDL, lvs_StartupDirectory);
lvs_FileName := '/'+LinkName+'.lnk';
lvs_LinkFilename := lvs_StartupDirectory + lvs_FileName;
lvo_PFile.Save(pWChar(lvs_LinkFilename),FALSE);
end;

调用:
CreateLink('程序名','快捷方式名称',lkDesktop);//在桌面上创建快捷方式

//放在启动里
procedure TForm1.WriteRegAutoRun(FileName:string);
var
Regf:TRegistry;
begin
Regf:=TRegistry.Create;
Regf.RootKey:=HKEY_LOCAL_MACHINE;

if Length(FileName)>0 then
try
RegF.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',false);
RegF.WriteString('YourProgram',FileName);
except
end;
RegF.CloseKey;
RegF.Free;
end;
 
接受答案了.
 
后退
顶部