博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

怎样在程序中调用批处理文件

Posted on 2006-12-17 18:24  ╁蓝驿┲→  阅读(748)  评论(0编辑  收藏  举报

怎样在程序中调用批处理文件?
话题590693的标题是: 怎样在程序中调用批处理文件? (100分)
分类:控件 - 使用 huang_sir (2001-07-25 8:55:00) 
我想在delphi程序中运行批处理文件,如何调用?请教
 
笨笨 (2001-07-25 9:28:00) 
ShellExecute(Self.Handle, 'open', 'xx.bat', '', '', SW_SHOWNORMAL);

 
wind_cloudy (2001-07-25 9:52:00) 
用winexec更简单一些,
winexec('c:\a.bat',SW_SHOWNORMAL);
 
PPMouse (2001-07-25 20:55:00) 
同意楼上的。
 
sonie (2001-07-25 21:15:00) 
当然也可以用createprocess,不过麻烦一点
 
friendkey (2001-07-27 16:32:00) 
还是用SW_HIDE比较爽(如果你不希望看到DOS窗口的话)
 
zanpen2001 (2001-08-04 22:53:00) 
闲着没事写了个小程序,格式化A盘的,用Dos下的Format,下面的源码包括批处理文件
的创建以及在程序中对Command窗口的响应,就是当Format命令提示插入软盘和提示输入卷
标及是否格式化另一张盘时向窗口发送消息,比如回车,“y”键等。看了以后什么都明白了。

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button3: TButton;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  iehandle:thandle;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    ford:textfile;
begin
    assignfile(ford,'c:\a.bat');
    rewrite(ford);
    writeln(ford,'@echo off');
    writeln(ford,'format a:/q');
    writeln(ford,'@del %0');
    writeln(ford,#13#10);
    closefile(ford);
    winexec('c:\a.bat',sw_normal);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
    iehandle:=findwindow(nil,'C:\WINNT\SYSTEM32\CMD.EXE');
    postmessage(iehandle,wm_KEYDOWN,VK_RETURN,0);
    postmessage(iehandle,wm_keydown,vk_return,0);
    postmessage(iehandle,wm_keydown,78,0);
    postmessage(iehandle,wm_keydown,vk_return,0);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
    postmessage(iehandle,wm_keydown,78,0);
    postmessage(iehandle,wm_keydown,vk_return,0);
end;

end.

 
amo (2002-05-17 11:43:00) 
多人接受答案了。
 

sonie-24,wind_cloudy-24,zanpen2001-28,笨笨-24,的回答最终被接受。
 
本文地址:http://delphi.apub.org/doc/2006/07/12/10/54/51/179105.html
原文出处:http://www.delphibbs.com/
本站声明: 本站资源均来自于互联网,如果本站侵