type ShortcutType = (ST_DESKTOP, ST_SENDTO, ST_QUICKLAUNCH, ST_STARTMENU);//定义一个数据类型 procedure CreateShortcut(FileName :string; Description :string; arguements :string; Location :ShortcutType); var cObj :IUnknown; sLink :IShellLink; pFile :IPersistFile; sDir :string; lName :string; spath :string; wFileName :WideString; mReg :TRegistry; key :string; tmp :string; begin cObj :=CreateComObject(CLSID_ShellLink); //创建COM对象 sLink :=cObj as IShellLink; //COM对象转化为IShellLink型接口 pFile :=cObj as IPersistFile; //COM对象转化为IPersistFile型接口 //获取路径 sPath :=ExtractFilePath(FileName); with sLink do begin SetPath(PChar(FileName)); //设置执行文件名 SetArguments(PChar(arguements)); //设置执行参数 SetDescription(Pchar(Description)); //设置描述信息 SetWorkingDirectory(PChar(sPath)); //设置工作路径,即执行程序所在目录 end; //获取各快捷方式的实际目录 mReg :=TRegistry.Create; with mReg do begin RootKey :=HKEY_CURRENT_USER; key :=REGSTR_PATH_EXPLORER; //Delphi在单元RegStr中定义的常量 tmp :=key + '\Shell Folders'; |