在delphi中建立程序的快捷方式--并将快捷方式放在开始->程序->的启动组中

类别:Delphi 点击:0 评论:0 推荐:

前几天应客户要求写这个东西,其实用VB,VC可能更快些,不过,我还是喜欢用DELPHI

首先 uses ActiveX,ComObj,StdCtrls,ShlObj,FileCtrl;

在指定文件夹建立当前应用程序才的快捷方式

procedure Tform1.MakeLink(Foldername:string;proName, lnkName, Description: string);
var
  WorkDir, DestName: string;
  aObj: IUnknown;
  MyLink: IShellLink;
  MyPFile: IPersistFile;
  WFileName: WideString;
  curdir: array[0..100] of Char;
begin
  DestName := Foldername + lnkName;
  aObj := CreateComObject(CLSID_ShellLink);
  MyLink := aObj as IShellLink;
  MyPFile := aObj as IPersistFile;
  GetCurrentDirectory(sizeof(curdir), curdir);
  workdir := curdir;
  proname := trim(WorkDir)+'\'+proname;
  with MyLink do
  begin

    SetShowCmd(SW_NORMAL);
    SetArguments('');
    SetDescription(pChar(Description));
    SetPath(pChar(proName));
    SetWorkingDirectory(pChar(WorkDir));
  end;
  CreateDir(ExtractFilePath(DestName));
  WFileName := DestName;
  MyPFile.Save(PWChar(WFileName), False);
end;

//获得开始->程序->的启动组 的路径

function Tform1.GetSpecialFolder: string;//get starup Floder
var
  Pidl: PItemIDList;
  handle : THandle;
  Comp: TComponent;
  LinkDir : string;
begin
  result:='';
  Comp := self;//self.owner;
  handle := (Comp as TForm).handle;
  if SUCCEEDED(SHGetSpecialFolderLocation(handle, CSIDL_COMMON_STARTUP, Pidl))  then //别的特殊路径也可以用CSIDL_COMMON或的,在delphi中查一下就可以了

 begin
       SetLength(LinkDir, MAX_PATH);
       SHGetPathFromIDList(Pidl, PChar(LinkDir));
       SetLength(LinkDir, StrLen(PChar(LinkDir)));
       result:=linkdir+'\';

  end;
end;
//
部分内容借鉴了大富翁bbs上的内容

本文地址:http://com.8s8s.com/it/it4992.htm