unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellApi,registry;
//别忘了引用ShellApi
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//隐藏当前程序主窗体
application.ShowMainForm:=false;
//设置当前目录,这样bat文件出现关于上下文调用时不会出错
SetCurrentDir('D:/Program Files/Apache Software Foundation/Tomcat 5.0/bin/');
ShellExecute(Handle,'open',
'D:/Program Files/Apache Software Foundation/Tomcat 5.0/bin/catalina.bat',
'run',
nil,
SW_HIDE);//关于shellExecute的参数请google,这里解释run是运行catalina.bat必须加的参数
{
如果直接调用startup.bat的话无法实现窗体隐藏,因为startup又调用了其他文件,
改语句只能隐藏当前的startup.bat,通过对startup.bat进行分析,我发现其实它
的功能就是判断Java环境变量和Tomcat是否配置正确,然后调用 catalina.bat,所以
上面我在可以保证配置正确的情况下直接调用catalina.bat
SetCurrentDir('D:/Program Files/Apache Software Foundation/Tomcat 5.0/bin/');
WinExec('D:/Program Files/Apache Software Foundation/Tomcat 5.0/bin/startup.bat',SW_HIDE);
}
{
ShellExecute(Handle,'open',
'D:/test.bat',
'//MS//Tomcat5',
nil,
SW_HIDE);
}
application.Terminate;
end;
end.
{
* 运行一个程序:
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);
* 打开一个HTML网页,本地的或远程的:
ShellExecute(Handle, 'open', PChar(' ), nil, nil, SW_SHOW);
* 打开一个文本文件:
ShellExecute(Handle, 'open', PChar('c:/test/readme.txt'), nil, nil, SW_SHOW);
打开HTML帮助文件: ShellExecute(Handle, 'open', PChar('c:/windows/help/calc.chm'), nil, nil, SW_SHOW);
* 浏览文件夹:
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);
}