The IDM offers some API for client applications : http://www.internetdownloadmanager.com/support/idm_api.html

How can I do this via Delphi?

有帮助吗?

解决方案

ok. let suppose we have IDM installed.

seems IDManTypeInfo.tlb library does not contain information about data types of IDM library. In this case, the only way to use this library is to rewrite c++ header files to Delphi:

unit IDMan;

interface
uses windows, ActiveX;

const
    CLSID_CIDMLinkTransmitter : TGUID = '{AC746233-E9D3-49CD-862F-068F7B7CCCA4}';

    IID_ICIDMLinkTransmitter  : TGUID = '{4BD46AAE-C51F-4BF7-8BC0-2E86E33D1873}';
    IID_ICIDMLinkTransmitter2 : TGUID = '{94D09862-1875-4FC9-B434-91CF25C840A1}';
type
    ICIDMLinkTransmitter = interface(IInterface)
        ['{4BD46AAE-C51F-4BF7-8BC0-2E86E33D1873}']

        function SendLinkToIDM(
            Url : WideString;
            Referer : WideString;
            Cookies : WideString;
            Data: WideString;
            User: WideString;
            Password: WideString;
            LocalPath: WideString;
            LocalFileName: WideString;
            Flags : longint):HRESULT; stdcall;
    end;

    ICIDMLinkTransmitter2 = interface(ICIDMLinkTransmitter)
        ['{94D09862-1875-4FC9-B434-91CF25C840A1}']
        function SendLinkToIDM2(
            Url : WideString;
            Referer: WideString;
            Cookies: WideString;
            Data: WideString;
            User: WideString;
            Password: WideString;
            LocalPath: WideString;
            LocalFileName: WideString;
            Flags : longint;
            reserved1 : Variant;
            reserved2 :Variant): HResult; stdcall;

        function SendLinksArray(
            location : WideString;
            LinksArray : PSafeArray):HResult; stdcall;
    end;

implementation

end.

add this unit to your project and try to use the next code:

uses IDMan, ComObj;
....
procedure TMainForm.TestIDM();
var lt : ICIDMLinkTransmitter;
begin
    lt := CreateComObject(CLSID_CIDMLinkTransmitter) as ICIDMLinkTransmitter;
    lt.SendLinkToIDM('http://www.internetdownloadmanager.com/trans_kit.zip', 'teran.karelia.pro','','','','','','', 0);
end;

I have no IDM installed, so I didn't check this code. I'm not sure it is 100% correct, but try it.

其他提示

uses ShellAPI,Registry;

function GetProgramFilesDir: string;
begin
  with TRegistry.Create do begin
  try
    RootKey := HKEY_LOCAL_MACHINE;
    OpenKeyReadOnly('SOFTWARE\Microsoft\Windows\CurrentVersion');
    Result := ReadString('ProgramFilesDir');
  finally
   Free;
  end;
  end;
end;


var url:string;

begin
url:='http:\\yourfile';
if FileExists(GetProgramFilesDir+'\Internet Download Manager\IDMan.exe') then
ShellExecute(Handle, 'open',pchar('"'+GetProgramFilesDir+'\Internet Download Manager\IDMan.exe"'),PChar(' /d "'+url+'"'),nil, 1) else
ShellExecute(Handle, 'open',nil,PChar(url),nil, 1) ; //1=show --
 end;

work 100%

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top