ShellExecute

//ShellExecute 

ShellExecute(
hWnd: HWND; {指定父窗口句柄}
Operation: PChar; {指定动作, 譬如: open、print}
FileName: PChar; {指定要打开的文件或程序}
Parameters: PChar; {给要打开的程序指定参数; 如果打开的是文件这里应该是 nil}
Directory: PChar; {缺省目录}
ShowCmd: Integer {打开选项}
): HINST; {执行成功会返回应用程序句柄; 如果这个值 <= 32, 表示执行错误}

//返回值可能的错误有:
= 0 {内存不足}
ERROR_FILE_NOT_FOUND = 2; {文件名错误}
ERROR_PATH_NOT_FOUND = 3; {路径名错误}
ERROR_BAD_FORMAT = 11; {EXE 文件无效}
SE_ERR_SHARE = 26; {发生共享错误}
SE_ERR_ASSOCINCOMPLETE = 27; {文件名不完全或无效}
SE_ERR_DDETIMEOUT = 28; {超时}
SE_ERR_DDEFAIL = 29; {DDE 事务失败}
SE_ERR_DDEBUSY = 30; {正在处理其他 DDE 事务而不能完成该 DDE 事务}
SE_ERR_NOASSOC = 31; {没有相关联的应用程序}

//ShowCmd 参数可选值:
SW_HIDE = 0; {隐藏}
SW_SHOWNORMAL = 1; {用最近的大小和位置显示, 激活}
SW_NORMAL = 1; {同 SW_SHOWNORMAL}
SW_SHOWMINIMIZED = 2; {最小化, 激活}
SW_SHOWMAXIMIZED = 3; {最大化, 激活}
SW_MAXIMIZE = 3; {同 SW_SHOWMAXIMIZED}
SW_SHOWNOACTIVATE = 4; {用最近的大小和位置显示, 不激活}
SW_SHOW = 5; {同 SW_SHOWNORMAL}
SW_MINIMIZE = 6; {最小化, 不激活}
SW_SHOWMINNOACTIVE = 7; {同 SW_MINIMIZE}
SW_SHOWNA = 8; {同 SW_SHOWNOACTIVATE}
SW_RESTORE = 9; {同 SW_SHOWNORMAL}
SW_SHOWDEFAULT = 10; {同 SW_SHOWNORMAL}
SW_MAX = 10; {同 SW_SHOWNORMAL}


{在uses中引入 ShellAPI}
{打开计算器}
ShellExecute(Handle, 'open', 'calc.exe', 0, 0, SW_SHOWNORMAL);

{打开一个记事本}
ShellExecute(Handle, 'open', 'C:\新建文本文档.txt', 0, 0, SW_SHOWNORMAL);

{打开网页}
ShellExecute(Handle, 'open', 'www.baidu.com', 0, 0, SW_SHOWNORMAL);

{有指定的IE打开网页}
ShellExecute(Handle, 'open', 'iexplore.exe', 'www.baidu.com', 0, SW_SHOWNORMAL);

{发送邮件}
ShellExecute(Handle, 'open', 'mailto:[email protected]', 0, 0, SW_SHOWNORMAL);

{打开当前程序的文件夹}
ShellExecute(handle, 'open', '', 0, 0,SW_SHOWNORMAL);

{打开指定文件夹}
ShellExecute(Handle, 'open', 'Explorer.exe', 'C:\Windows', 0,SW_SHOWNORMAL);

{打开文件位置 并选中这个文件}
procedure TForm1.Button1Click(Sender: TObject);
var
    FilePath: string;
begin
    FilePath := 'C:\Program Files\Delphi7-Lite\Bin\brcide.dll';
    ShellExecute(handle, nil,PChar( 'explorer.exe'),PChar( 'e/,' + '/select, ' + FilePath), nil,SW_SHOWNORMAL);
end;

{打开资源管理器}
ShellExecute(handle, 'explore', 'c:\', 0, 0, SW_SHOWNORMAL);

{打印RTF文件}
shellExecute(handle, nil, 'write.exe', 'c:\文档.rtf /p', nil, SW_SHOWNORMAL);

{打开Reg文件,注意路径不要带有空格}
ShellExecute(handle, nil, 'regedit.exe', 'C:\Users\Administrator\Desktop\winiso.reg', nil,SW_SHOWNORMAL);

{打开 系统 日期和时间 对话框}
ShellExecute(Handle, 'open', 'control', 'date/time', nil, SW_SHOWNORMAL);



//打开完美世界

procedure TForm1.AdvSmoothButton9Click(Sender: TObject);

var

  Path:string;

begin

   Path:='D:\Administrator\Documents\Games\完美世界国际版\element\elementclient.exe';

   ShellExecute(Handle,'open', PChar(Path), PChar(' game:cpw'), PChar(ExtractFilePath(Path) ), SW_SHOW);

end;

http://www.ghoffice.com/bbs/read.php?tid-70734.html

 





你可能感兴趣的:(execute)