2

Executing Control Panel Itemsで、MSDN は次のように述べています。

Windows Vista の正規名

Windows Vista 以降では、コマンド ラインからコントロール パネル項目を起動するための推奨される方法は、コントロール パネル項目の正規名を使用することです。

MicrosoftのWebサイトによると、これは機能するはずです:

次の例は、アプリケーションがコントロール パネル項目の Windows Update を WinExec で開始する方法を示しています。

WinExec("%systemroot%\system32\control.exe /name Microsoft.WindowsUpdate", SW_NORMAL);

Delphi 2010の場合、私は試しました:

var
  CaptionString: string;
  Applet: string;
  Result: integer;
  ParamString: string;
CaptionString := ListviewApplets1.Items.Item[ ListviewApplets1.ItemIndex ].Caption;
if CaptionString = 'Folder Options' then
    { 6DFD7C5C-2451-11d3-A299-00C04F8EF6AF }
    Applet := 'Microsoft.FolderOptions'
  else if CaptionString = 'Fonts' then
    {93412589-74D4-4E4E-AD0E-E0CB621440FD}
    Applet := 'Microsoft.Fonts'
  else if CaptionString = 'Windows Update' then
    { 93412589-74D4-4E4E-AD0E-E0CB621440FD }
    Applet := 'Microsoft.WindowsUpdate'
  else if CaptionString = 'Game Controllers' then
    { 259EF4B1-E6C9-4176-B574-481532C9BCE8 }
    Applet := 'Microsoft.GameControllers'
  else if CaptionString = 'Get Programs' then
    { 15eae92e-f17a-4431-9f28-805e482dafd4 }
    Applet := 'Microsoft.GetPrograms'
//...

ParamString := ( SystemFolder + '\control.exe /name ' ) + Applet;
WinExec( ParamString, SW_NORMAL); <= This does not execute and when I trapped the error it returned ERROR_FILE_NOT_FOUND.

ExecAndWait( ParamString ) メソッドを試してみたところ、WinExec で使用されるものと同じ ParamString で完全に機能します。

ParamString := ( SystemFolder + '\control.exe /name ' ) + Applet;
ExecAndWait( ParamString ); <= This executes and Runs perfectly

私が使用した ExecAndWait メソッドは、Windows.CreateProcess を呼び出します。

if Windows.CreateProcess( nil, PChar( CommandLine ), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo ) then
  begin
    try

WinExec には別の ParamString が必要ですか、それとも WinExec でこれを間違っていますか? 完全な ExecAndWait メソッドを投稿しませんでしたが、誰かが見たい場合は投稿できます。

4

2 に答える 2

3

@Bill WinExec関数は非推奨です。

MSDN サイトから

この関数は、16 ビット Windows との互換性のためにのみ提供されています。アプリケーションは CreateProcess 関数を使用する必要があります

CreateProcess関数を使用してこのサンプルを試してください

program ProjectTest;

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils;

var
  App        : String;
  Params     : String;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  try
   App    := 'control.exe';
   Params := '/Name Microsoft.GetPrograms';
   FillChar(StartupInfo, SizeOf(StartupInfo), 0);
   StartupInfo.cb := SizeOf(StartupInfo);
   if not CreateProcess(nil, PChar(App+' '+Params), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo) then
    RaiseLastOSError;
    //Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
于 2010-05-25T22:21:00.753 に答える
0

'control.exe /name' + アプレットのみを含むように ParamString を変更して、WinExec で実行してみてはいかがでしょうか?

于 2010-05-25T20:39:44.683 に答える