如何动态的生成一个快捷方式文件,并使其指向某个程序,并运行该快捷方式文件

解决方案 »

  1.   

    const 
    CCH_MAXNAME=255;LNK_RUN_MIN=7;LNK_RUN_MAX=3;LNK_RUN_NORMAL=1;type LINK_FILE_INFO=recordFileName:array[0..MAX_PATH] of char;WorkDirectory:array[0..MAX_PATH] of char;IconLocation:array[0..MAX_PATH] of char;IconIndex:integer;Arguments:array[0..MAX_PATH] of char;Description:array[0..CCH_MAXNAME] of char;ItemIDList:PItemIDList;RelativePath:array[0..255] of char;ShowState:integer;HotKey:word;end;function CreateLinkFile(const info:LINK_FILE_INFO;const DestFileName:string=''):boolean;varanobj:IUnknown;shlink:IShellLink;pFile:IPersistFile;wFileName:widestring;beginwFileName:=destfilename;anobj:=CreateComObject(CLSID_SHELLLINK);shlink:=anobj as IShellLink;pFile:=anobj as IPersistFile;shlink.SetPath(info.FileName);shlink.SetWorkingDirectory(info.WorkDirectory);shlink.SetDescription(info.Description);shlink.SetArguments(info.Arguments);shlink.SetIconLocation(info.IconLocation,info.IconIndex);// shlink.SetIDList(info.ItemIDList);shlink.SetHotkey(info.HotKey);shlink.SetShowCmd(info.ShowState);shlink.SetRelativePath(info.RelativePath,0);if DestFileName='' thenwFileName:=ChangeFileExt(info.FileName,'lnk');result:=succeeded(pFile.Save(pwchar(wFileName),false));end;