我在桌面上放一个快捷方式,我怎么来获取主程序所在目录的路径?

解决方案 »

  1.   

    右击快捷方式—>属性—>查找目标。
      

  2.   

    http://www.csdn.net/Develop/Read_Article.asp?Id=2230
    http://expert.csdn.net/Expert/topic/1294/1294027.xml?temp=.7984583
      

  3.   

    function LinkFileInfo(const lnkFileName:string;var info:LINK_FILE_INFO;const bSet:boolean):boolean;var hr:hresult; psl:IShelllink; wfd:win32_find_data; ppf:IPersistFile; lpw:pwidechar; buf:pwidechar;begin result:=false; getmem(buf,MAX_PATH); try if SUCCEEDED(CoInitialize(nil)) then if (succeeded(cocreateinstance(clsid_shelllink,nil,clsctx_inproc_server,IID_IShellLinkA,psl))) then begin   hr:=psl.QueryInterface(iPersistFile,ppf);   if succeeded(hr) then   begin     lpw:=stringtowidechar(lnkfilename,buf,MAX_PATH);     hr := ppf.Load(lpw, STGM_READ);     if succeeded(hr) then     begin       hr := psl.Resolve(0, SLR_NO_UI);       if succeeded(hr) then       begin         if bSet then         begin           psl.SetArguments(info.Arguments);           psl.SetDescription(info.Description);           psl.SetHotkey(info.HotKey);           psl.SetIconLocation(info.IconLocation,info.IconIndex);           psl.SetIDList(info.ItemIDList);           psl.SetPath(info.FileName);           psl.SetShowCmd(info.ShowState);           psl.SetRelativePath(info.RelativePath,0);           psl.SetWorkingDirectory(info.WorkDirectory);           result:=succeeded(psl.Resolve(0,SLR_UPDATE));         end         else         begin           psl.GetPath(info.FileName,MAX_PATH, wfd,SLGP_SHORTPATH );           psl.GetIconLocation(info.IconLocation,MAX_PATH,info.IconIndex);           psl.GetWorkingDirectory(info.WorkDirectory,MAX_PATH);           psl.GetDescription(info.Description,CCH_MAXNAME);           psl.GetArguments(info.Arguments,MAX_PATH);           psl.GetHotkey(info.HotKey);           psl.GetIDList(info.ItemIDList);           psl.GetShowCmd(info.ShowState);           result:=true;         end;       end;     end;   end;end; finally freemem(buf); end;end;
      

  4.   

    ExtractFilePath(Application.ExeName)+'你要打开的程序'
      

  5.   

    ExtractFilePath(ParamStr(0))这个就是你主程序的位置(不是主程序全路径名)