Delphi。 ShellExecute 命令在 Win 7 上正常运行,但在 Win 8 上运行不正常

Delphi. ShellExecute command performs properly on Win 7 but not Win 8

我正在使用 Delphi 2010 在 32 位 Windows 7 PC 上编程。

当 运行 在我的 PC 上以管理员身份运行时,以下代码有效。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, 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
  ShellExecute(0,'open','command','/c ipconfig /all > testipco.txt','',0);
  showmessage('Test IP Config file should be written');
end;

end.

输出文件 TESTIPCO.TXT 并包含与在命令提示符中键入 ipconfig /all 相同的结果 window。

当我以管理员身份在 64 位 Windows 8.1 PC 上编译文件并 运行 时,程序似乎 运行 OK,显示消息(没有错误) 但未生成文件 TESTIPCO.TXT。

即使 运行 在 Windows 8 机器上将 exe 与兼容性设置为 运行 作为 Windows 7 也不起作用。

我只是想不通为什么会这样。我希望你们中的一位聪明人能够引导我朝着正确的方向前进。

您尝试过 cmd.exe 吗? Command 有点陈旧。