var StartupInfo:TStartupInfo;
    ProcessInfo:TProcessInformation;
    commandLine: string;
begin
  commandLine := 'mode com1 9600,n,8,1';
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := 1;
  StartupInfo.lpReserved := nil;
  StartupInfo.lpReserved2 := nil;  CreateProcess(nil,
                commandLine,
                nil,
                nil,
                false,
                0,
                nil,
                nil,
                StartupInfo,
                ProcessInfo);
end;想执行一个DOS程序,但好象没有什么反映呢,连个COPY命令都不好使
不太会用这个函数

解决方案 »

  1.   

    我用WinExec(commandLine,SW_SHOW)怎么好象都不好使呢?这是为什么呢
      

  2.   

    把commandLine换成pchar(commandLine)也不好使
    并且commandLine := 'mode com1 9600,n,8,1';改成
    commandLine := 'c;\\winnt\\system32\\mode.exe com1 9600,n,8,1';
    也不行!!!我算是没折了
      

  3.   

    我想问一下TStartupInfo,TProcessInformation是个什么控件?我在帮助里没有找到他们的解释,希望楼主介绍一下。最好提供相关的介绍文章。新手上路不要见笑!
      

  4.   

    是DEPHI中封装的STARTUPINFO这个结构体
    见原码得  {$EXTERNALSYM _STARTUPINFOA}
      TStartupInfo = _STARTUPINFOA;
      STARTUPINFO = _STARTUPINFOA;StartupInfo:TStartupInfo;等同于C中的StartupInfo:STARTUPINFO;
      

  5.   

    做一个bat文件,内容是mode com1 9600,n,8,1
    commandline="test.bat";
    应该就可以了
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);
    var StartupInfo:TStartupInfo;
        ProcessInfo:TProcessInformation;
        commandLine: string;
    begin
      commandLine := 'Rundll32.exe Shell32.dll,ShellExec_RunDLL mode com1 9600,n,8,1';
      FillChar(StartupInfo,Sizeof(StartupInfo),#0);
      StartupInfo.cb := Sizeof(StartupInfo);
      StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartupInfo.wShowWindow := 1;
      StartupInfo.lpReserved := nil;
      StartupInfo.lpReserved2 := nil;  if CreateProcess(nil,
                    PChar(commandLine),
                    nil,
                    nil,
                    false,
                    0,
                    nil,
                    nil,
                    StartupInfo,
                    ProcessInfo) = true then
        showmessage('ok');
    end;
    以上只能在winnt以上系统下才能使用。:)
      

  7.   

    DOS 程序用
    WINEXEC就可以了
      

  8.   

    用WINEXEC根本就起不来的,我已经试过了
      

  9.   

    TO  ouyang75928(Thinking in Pascal) ( ) 
    谢谢了,NT下运行DOS命令是否都要加上Rundll32.exe, shell32.exe, shellexec_rundll呢?
      

  10.   

    TO  ouyang75928(Thinking in Pascal) ( )  
    那为什么象COPY那种的命令则可以直接运行呢?而MODE这个也是exe的文件则必须要加上外壳才好使呢
      

  11.   

    更确切的说Rundll32.exe, shell32.exe, shellexec_rundll是模拟windows下面的run命令。
    mode com1 9600,n,8,1这些都是参数来的,copy是函数。
      

  12.   

    http://expert.csdn.net/Expert/topic/2234/2234728.xml?temp=.7062494
    拜托也帮我看看这个帖子~~是DEPHI下的浮点如何比较?