zoukankan      html  css  js  c++  java
  • Delphi 根据快捷方式路径取源文件地址


    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    uses shlobj, ActiveX, ComObj;

    function ExeFromLink(const linkname: string): string;
    var
      link: IShellLink;
      storage: IPersistFile;
      filedata: TWin32FindData;
      buf: array[0..MAX_PATH] of Char;
      widepath: WideString;
    begin
      OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
        IShellLink, link));
      OleCheck(link.QueryInterface(IPersistFile, storage));
      widepath := linkname;
      Result := 'unable to resolve link';
      if Succeeded(storage.Load(@widepath[1], STGM_READ)) then
        if Succeeded(link.Resolve(GetActiveWindow, SLR_NOUPDATE)) then
          if Succeeded(link.GetPath(buf, sizeof(buf), filedata, SLGP_UNCPRIORITY))
            then
            Result := buf;
      storage := nil;
      link := nil;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
       Caption:=ExeFromLink('D:AdministratorDesktopProject1.lnk');
    end;

    end.





    附件列表

    • 相关阅读:
      我所理解的NAT
      H3C防火墙安全策略故障排查思路
      职场建议
      小型企业典型网络内部拓扑
      echo&printf
      笔挺站立 昂首挺胸
      Jordan Peterson 的建议
      刚才思考的两个问题
      高手的见解
      一个企业网络管理人员的注意事项
    • 原文地址:https://www.cnblogs.com/xe2011/p/3641433.html
    Copyright © 2011-2022 走看看