见题,给个例子!shellexceute 怎么用?

解决方案 »

  1.   

    WinExec('NOTEPAD.EXE',SW_NORMAL);这个行不行?
      

  2.   

    uses shellAPI;
    //ShellExecute(hWnd: HWND; Operation, FileName, Parameters,
      //Directory: PChar; ShowCmd: Integer): ; stdcall;
    var
      hReadme: HINST;hReadme := ShellExecute(0, 'open', 'notepad', 0, 0, SW_MAXIMIZE);
    if hReadme <= 32 then
    ShowMessage('fail');
      

  3.   

    来个更加漂亮的,
    var
      hReadme: HINST;
      se: SHELLEXECUTEINFO;
      hInstallProcess: THandle;
    begin
    ZeroMemory ( @se, sizeof ( SHELLEXECUTEINFO));
    se.cbSize := sizeof(SHELLEXECUTEINFO);
    se.fMask := SEE_MASK_NOCLOSEPROCESS;
    se.Wnd := 0;
    se.lpFile := 'notepad';    //运行的文件。
    se.nShow := SW_MAXIMIZE;
    se.lpVerb := 'open';
    se.lpParameters := nil;
    se.lpDirectory := nil;
    se.nShow := SW_MAXIMIZE;
    se.hProcess := 0;
    se.hInstApp := 0; if ShellExecuteEx(@se) = true then
          begin
    hInstallProcess := se.hProcess;
            showmessage(IntToStr(hInstallProcess));
          end;
    ShellExecuteEx在运行以后可以取出进程ID,可以继续对该程序进行控制啦。
      

  4.   

    不是WinExec就ShellExecute了
    CreateProcess比较麻烦的
      

  5.   

    //hyadd 为了控制外部报表打印程序
      MyHandle: THandle;
      MyStartupInfo: TStartupInfo;
      MyProcessInfo: TProcessInformation;
      //hyadd end; //hyadd 为了控制外部报表打印程序
      procedure ExecuteApp(MyPath: String);
      procedure CloseApp(MyHandle: THandle);
      //hyendprocedure ExecuteApp(MyPath: String);
    begin
      FillChar(MyStartupInfo, SizeOf(MyStartupInfo), 0);
      //清除MyStartupInfo中的数据  MyStartupInfo.cb:=SizeOf(MyStartupInfo);  CreateProcess(PChar(MyPath), nil, nil, nil, False,
      DETACHED_PROCESS, nil, nil, MyStartupInfo,MyProcessInfo);  MyHandle:=MyProcessInfo.hProcess;
      //把执行的程序的句柄赋值给MyHandle,它会在终止程序时用到
    end;procedure CloseApp(MyHandle: THandle);
    begin
    TerminateProcess(MyHandle, 0);
    end;