Coping File On Network

program FlashPlayer;

uses
Forms, windows, sysutils, classes, comobj, dialogs,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}
{$R FlashOCX.RES}

type
TRegFunc = function : HResult; stdcall;

var
aSystemDir : array[0..2047] of Char;
aShortPath : array[0..2047] of Char;
sSystemDir : String;
sCommand : String;
LibHandle : Cardinal;
LibFunc : TRegFunc;

// Menjalankan program dan menunggu sampai selesai
function ExecuteAndWait(FileName: String;
Visibility : Integer ) : Cardinal;
var
AppName : array[0..512] of char;
CurrentDir : array[0..255] of char;
WorkDir : String;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
begin
StrPCopy(AppName, FileName);
GetDir(0, WorkDir);
StrPCopy(CurrentDir, WorkDir);

FillChar(StartupInfo, Sizeof(StartupInfo), #0);

StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;

if (not CreateProcess(nil, AppName, nil, nil, false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil, CurrentDir, StartupInfo,
ProcessInfo)) then
begin
Result := $FFFFFFFF; {pointer ke PROCESS_INF}
MessageBox(Application.Handle,
PChar(SysErrorMessage(GetLastError)),
'Kesalahan!', 0 );
end
else
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end;
end;

// Gunakan fungsi berikut jika Anda menyertakan resource
// SWFLASH.OCX pada file EXE
function CreateOCXFromResource : boolean;
var
ResStream : TResourceStream;
FileStream : TFileStream;
begin
result := true;
ResStream := TResourceStream.Create(0,'Flash',RT_RCDATA);
try
FileStream := TFileStream.Create(sSystemDir +
'\SWFLASH.OCX', fmCreate);
// mengkopi file SWFLASH.OCX dari resource ke
// direktori sistem Windows
try
FileStream.CopyFrom(ResStream, 0);
finally
FileStream.Free;
end;
except on EFCreateError do
begin
ShowMessage('Tidak dapat membuat file SWFLASH.OCX');
Result := false;
end;
end;
ResStream.Free;
end;

begin
GetSystemDirectory(aSystemDir,2047);
sSystemDir := aSystemDir;

Application.Initialize;
try
Application.CreateForm(TForm1, Form1);
except
//jika file SWFLASH.OCX tidak ditemukan
//atau belum diregister
On EOleSysError Do
begin
if CreateOCXFromResource then // mengkopi SWFLASH.OCX
begin
try
{Meregister file OCX}
LibHandle := LoadLibrary(PChar(sSystemDir +
'\SWFLASH.OCX'));
if (LibHandle >= 32) // jika file SWFLASH.OCX
then // berhasil dibuka
begin
LibFunc := GetProcAddress(LibHandle, 'DllRegisterServer');
if (Assigned(LibFunc) = TRUE) then
begin
GetShortPathName(PChar(sSystemDir+'\SWFLASH.OCX'),
aShortPath,2047);
sCommand := Format('%s\regsvr32.exe /s %s',
[sSystemDir, aShortPath]);
ExecuteAndWait(sCommand, SW_HIDE);
end;
FreeLibrary(LibHandle);
end;

// coba membuat form kembali
try
Application.CreateForm(TForm1, Form1);
except
ShowMessage('Tidak dapat menemukan Macromedia Shockwave Flash.');
end;

except
ShowMessage('Tidak dapat meregister Macromedia Shockwave Flash.');
end; {Akhir registrasi file OCX}
end;
end;
end;
Application.Run;
end.

Share this

Related Posts

Previous
Next Post »