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.