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.





    附件列表

    • 相关阅读:
      爬虫基础 2.1 http原理
      爬虫基础 2.1 http原理
      3.29上午
      3.28
      3.27下午
      3.27上午
      3.24上午
      3.23下午
      3.23上午
      3.22上午
    • 原文地址:https://www.cnblogs.com/xe2011/p/3641433.html
    Copyright © 2011-2022 走看看