![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#16
|
|||
|
|||
|
вот так по крайней мере компилируется:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Wininet,registry;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
ShellAPI;
function RunProcess (path, args : String) : THandle;
var
si : TStartupInfo;
pi : TProcessInformation;
cmdLine : String;
Begin
ZeroMemory(@si, sizeof(si));
cmdLine :='"' + path + '" ' + args;
if CreateProcess(nil, PCHAR(cmdLine) ,nil,nil,TRUE, 0 ,nil,nil,si, pi)
Then Result := pi.hProcess
Else Result := 0;
End;
function GetInetFile(const fileURL, FileName: string): boolean;
const
BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: file;
sAppName: string;
begin
Result := False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName),
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen);
until
BufferLen = 0;
CloseFile(f);
Result := True;
finally
InternetCloseHandle(hURL);
end;
finally
InternetCloseHandle(hSession);
end;
end;
function GetWinDir: string;
var
reg: TRegistry;
begin
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion',true);
Result:=reg.ReadString('PathName');
reg.CloseKey;
reg.Free;
end;
procedure InstallNETFramework;
begin
if DirectoryExists(GetWinDir+'\Microsoft.NET\Framework\v2.0.50727')=false then
begin
GetInetFile('http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe',ExtractFilePath(Application.ExeName)+'dotnetfx.exe');
Sleep(1000);
ShellExecute(form1.handle,'open','bat.bat',nil,nil,SW_SHOW);
Sleep(1000000);
RunProcess('moy.exe','');
end;
end;
end. |
|
#17
|
|||
|
|||
|
ага спасибо, уже компилится, но файл качать прога всеравно отказывается
![]() |
|
#18
|
||||
|
||||
|
Код:
unit Unit1;
interface
uses
WinInet,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetTempPath: String;
var
buf: array [0..255] of Char;
l: Integer;
begin
l:=Windows.GetTempPath(SizeOf(buf), @buf);
if l>0 then Result:=Copy(buf, 0, l) else Result:='';
Result:=IncludeTrailingPathDelimiter(Result);
end;
function GetInternetFile(const AURL: String; AFileName: String): Boolean;
var
hInternet: Pointer;
hOpenUrl: Pointer;
data: array [0..$ffff] of Byte;
dummy: Cardinal;
filestream: TFileStream;
begin
Result:=False;
hInternet:=nil;
hOpenUrl:=nil;
try
hInternet:=InternetOpen('Mozilla/4.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if hInternet=nil then raise Exception.Create('InternetOpen: '+SysErrorMessage(GetLastError));
hOpenUrl:=InternetOpenUrl(hInternet, PChar(AURL), nil, 0, INTERNET_FLAG_NO_COOKIES or INTERNET_FLAG_RELOAD or INTERNET_FLAG_PRAGMA_NOCACHE, 0);
if hOpenUrl=nil then raise Exception.Create('InternetOpenUrl: '+SysErrorMessage(GetLastError));
filestream:=TFileStream.Create(AFileName, fmCreate);
try
while InternetReadFile(hOpenUrl, @data[0], $10000, dummy) do
if dummy>0 then filestream.Write(data, dummy) else Break;
Result:=True;
finally
filestream.Free;
end;
finally
if hOpenUrl<>nil then InternetCloseHandle(hOpenUrl);
if hInternet<>nil then InternetCloseHandle(hInternet);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not GetInternetFile('http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe',
GetTempPath+'dotnetfx.exe') then ShowMessage('oops');
end;
end. |