ShellExecute的多种用法


本文整理自网络,侵删。

 ShellExecute的多种用法
━━━━━━━━━━━━━━━━━━━━━━━━━━

use ShellAPI

ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件、打开一个目录、打印一个文件等等),并对外部程序有一定的控制。
  有几个API函数都可以实现这些功能,但是在大多数情况下ShellExecute是更多的被使用的,同时它并不是太复杂。下面举例说明它的用法。

打开应用程序
   ShellExecute(Handle, 'open', PChar('c:\test\app.exe'), nil, nil, SW_SHOW);
打开记事本,并打开一个文件(系统能识别记事本应用程序的路径,因此我们不必使用绝对路径)
   ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW);
打印一个文档
   ShellExecute(Handle, 'print', PChar('c:\test\test.doc'), nil, nil, SW_SHOW);
   注意:可能你会看到word暂时的被打开,但它会自动关闭。
打开一个HTML页面
   ShellExecute(Handle, 'open', PChar('http://www.3464.com/'), nil, nil, SW_SHOW);
你能通过一个已经注册的文件类型来打开应用程序
   ShellExecute(Handle, 'open', PChar('c:\test\readme.txt'), nil, nil, SW_SHOW);
用windows Explorer 打开一个目录
   ShellExecute(Handle, 'explore', PChar('c:\windows)', nil, nil, SW_SHOW);运行一个DOS命令并立即返回
   ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);
运行一个DOS命令并保持DOS窗口存在
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW); //从Memo1取得批处理命令并运行:
procedure TForm2.Button1Click(Sender: TObject);
begin
ExecBat(Handle,Memo1.Lines);
end;procedure ExecBat(Handle : HWND; AStrings : TStrings);
begin
AStrings.Add('del ExecBat.bat');
AStrings.SaveToFile('ExecBat.bat');
ShellExecute(Handle,'open',PChar('ExecBat.bat'),nil,nil,SW_HIDE);
AStrings.Delete(AStrings.Count - 1);
end;

相关阅读 >>

Delphi实现保存和读取图片的方法

Delphi获取本机或者网关的互联网ip地址

Delphi让listbox实现即指即显功能

Delphi 优化mdb文件

Delphi中ado异步执行方式

Delphi程序删除自己

Delphi 内存管理[2-3]

Delphi一句话获取本机ip

Delphi 读取全网站链接

Delphi如何在tmemo控件光标当前位置插入字符串

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...