最好能有例子

解决方案 »

  1.   

    打开记事本,并打开一个文件(系统能识别记事本应用程序的路径,因此我们不必使用绝对路径)
    ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW);
    HINSTANCE ShellExecute(
        HWND hwnd, // handle to parent window 
        LPCTSTR lpOperation, // pointer to string that specifies operation to perform
        LPCTSTR lpFile, // pointer to filename or folder name string
        LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters 
        LPCTSTR lpDirectory, // pointer to string that specifies default directory
        INT nShowCmd  // whether file is shown when opened
       )
      

  2.   

    googel: WinExec
    ShellExecute
      

  3.   

    ShellExecute很方便,而且能够完成你的要求
      

  4.   

    Use shellAPI;
    shellexecute(handle,'open',pchar(ExtractFilePath(Paramstr(0))+'Help.CHM'),nil,nil,sw_shownormal);
      

  5.   

    1.WinExec
    2.ShellExecute
    3.CreateProcess
      

  6.   

    1.WinExec 最方便,但只能调用EXE。例子:WinExec('calc',1);2.ShellExecute,可以调用任意文件,使用时必须先uses ShellAPI; 例子:ShellExecute(0,0,'calc',0,0,1);3.CreateProcess,可以调用任意文件,有十个参数,一般主要用作调用进程时返回进程ID。例如我调用一个外部程序后,1分钟后对它进行关闭,这个时候关闭时可以利用返回的进程ID来进行杀进程操作。4.用Run方法。你可以在你的程序中加载脚本,Js和VBS都有脚本Run方法的,可以直接加载文件,与ShellExecute等效。关于3,这里给出一个详细例子:
    //创建进程并在3秒后杀掉它
    procedure TForm1.Button2Click(Sender: TObject);
    var
      si:STARTUPINFO;
      pi:PROCESS_INFORMATION;
    begin
    FillChar(si, SizeOf(si),0);
    si.dwFlags := STARTF_USESHOWWINDOW;
    si.cb:=SizeOf(si);
    si.wShowWindow := SW_Show;
    CreateProcess(0,'calc.exe',nil, nil, False,NORMAL_PRIORITY_CLASS, nil, nil,si,pi);
    CloseHandle(pi.hProcess);
    Sleep(3000);
    TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS,FALSE,pi.dwProcessId),0);
    end;
      

  7.   

    ShellExecute(Handle,'open','msconfig.exe','','',SW_SHOW); 
    ShellExecute(Handle,'open','gpedit.msc','','',SW_SHOW); 
      

  8.   

    谁说WinExec只能调用.EXE文件?WinExec配合start命令,简直无敌。执行:
    WinExec(PChar('cmd /C start http://www.baidu.com/'), SW_HIDE); 看看打开了没有。
    如果没有特殊需求,WinExec配合start效果就不错了。