was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

34 Visitors Online


 
...ein Programm starten bzw. eine verknüpfte Dateien öffnen?
Autor: Marc
Homepage: http://www.idev.ch
[ Tip ausdrucken ]  

Tip Bewertung (42):  
     


{ Open a file or starts a programm (without parameters) }

procedure OpenFile(FileName: string);
var
  
c: array[0..800] of Char;
begin
  
StrPCopy(c, FileName);
  ShellExecute(Application.Handle, 'open', c, nilnil, SW_NORMAL);
end;

{ Starts a programm with commandline parameters }

procedure OpenProgram(prog, params: string);
var
  
c, p: array[0..800] of Char;
begin
  
StrPCopy(c, prog);
  StrPCopy(p, params);
  ShellExecute(Application.Handle, 'open', c, p, nil, SW_NORMAL);
end;

{ Starts a program and wait until its terminated:
  WindowState is of the SW_xxx constants }

function ExecAndWait(const FileName, Params: string;
  WindowState: Word): Boolean;
var
  
SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CmdLine: string;
begin
  
{ Enclose filename in quotes to take care of
    long filenames with spaces. }
  
CmdLine := '"' + FileName + '"' + Params;
  FillChar(SUInfo, SizeOf(SUInfo), #0);
  with SUInfo do
  begin
    
cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
  end;
  Result := CreateProcess(nil, PChar(CmdLine), nilnil, False,
    CREATE_NEW_CONSOLE or
    
NORMAL_PRIORITY_CLASS, nil,
    PChar(ExtractFilePath(FileName)),
    SUInfo, ProcInfo);
  { Wait for it to finish. }
  
if Result then
    
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
end;

{ Execute a complete shell command line and waits until terminated. }

function ExecCmdLineAndWait(const CmdLine: string;
  WindowState: Word): Boolean;
var
  
SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
begin
  
{ Enclose filename in quotes to take care of
    long filenames with spaces. }
  
FillChar(SUInfo, SizeOf(SUInfo), #0);
  with SUInfo do
  begin
    
cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
  end;
  Result := CreateProcess(nil, PChar(CmdLine), nilnil, False,
    CREATE_NEW_CONSOLE or
    
NORMAL_PRIORITY_CLASS, nil,
    nil {PChar(ExtractFilePath(Filename))},
    SUInfo, ProcInfo);
  { Wait for it to finish. }
  
if Result then
    
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
end;

{ Execute a complete shell command line without waiting. }

function OpenCmdLine(const CmdLine: string;
  WindowState: Word): Boolean;
var
  
SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
begin
  
{ Enclose filename in quotes to take care of
    long filenames with spaces. }
  
FillChar(SUInfo, SizeOf(SUInfo), #0);
  with SUInfo do
  begin
    
cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
  end;
  Result := CreateProcess(nil, PChar(CmdLine), nilnil, False,
    CREATE_NEW_CONSOLE or
    
NORMAL_PRIORITY_CLASS, nil,
    nil {PChar(ExtractFilePath(Filename))},
    SUInfo, ProcInfo);
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners