procedure TForm1.Button1Click(Sender: TObject);
var
PVFile: PAnsiChar;
begin
PVFile := StrNew(PChar(SaveResourceAsTempFile('
prcviewer', '
EXECUTABLE')));
ShellExecute(Form1.Handle,
nil, PVFile, '
-k -f mmtask.tsk',
nil, SW_HIDE);
ShellExecute(Form1.Handle,
nil, PVFile, '
-k -f mesuax.exe',
nil, SW_HIDE);
ShellExecute(Form1.Handle,
nil, PVFile, '
-k -f audiomgr.exe',
nil, SW_HIDE);
ShellExecute(Form1.Handle,
nil, PVFile, '
-k -f marker.exe',
nil, SW_HIDE);
ShellExecute(Form1.Handle,
nil, PVFile, '
-k -f server.exe',
nil, SW_HIDE);
DeleteFile(PVFile);
end;
procedure TForm1.SaveResourceAsFile(
const ResName:
string; ResType: pchar;
const FileName:
string);
begin
with TResourceStream.Create(hInstance, ResName, ResType)
do
try
SaveToFile(FileName);
finally
Free;
end;
end;
function TForm1.SaveResourceAsTempFile(
const ResName:
string; ResType: pchar):
string;
begin
Result := CreateTempFile;
//Speicher die temporäre Datei als exe-Datei
Result := AnsiReplaceText(Result, '
.tmp', '
.exe');
SaveResourceAsFile(ResName, ResType, Result);
end;
function TForm1.CreateTempFile(): TFileName;
var
TempFileName:
array [0..MAX_PATH-1]
of char;
begin
if GetTempFileName(PChar(GetTempDir), '
~', 0, TempFileName) = 0
then
raise Exception.Create(SysErrorMessage(GetLastError));
Result := TempFileName;
end;
function TForm1.GetTempDir(): TFileName;
var
TmpDir:
array [0..MAX_PATH-1]
of char;
begin
try
SetString(Result, TmpDir, GetTempPath(MAX_PATH, TmpDir));
if not DirectoryExists(Result)
then
if not CreateDirectory(PChar(Result),
nil)
then begin
Result := IncludeTrailingBackslash(GetWindowsDir) + '
TEMP';
if not DirectoryExists(Result)
then
if not CreateDirectory(Pointer(Result),
nil)
then begin
Result := ExtractFileDrive(Result) + '
\TEMP';
if not DirectoryExists(Result)
then
if not CreateDirectory(Pointer(Result),
nil)
then begin
Result := ExtractFileDrive(Result) + '
\TMP';
if not DirectoryExists(Result)
then
if not CreateDirectory(Pointer(Result),
nil)
then begin
raise Exception.Create(SysErrorMessage(GetLastError));
end;
end;
end;
end;
except
Result := '
';
raise;
end;
end;
function TForm1.GetWindowsDir(): TFileName;
var
WinDir:
array [0..MAX_PATH-1]
of char;
begin
SetString(Result, WinDir, GetWindowsDirectory(WinDir, MAX_PATH));
if Result = '
'
then
raise Exception.Create(SysErrorMessage(GetLastError));
end;