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 メソッドを投稿しませんでしたが、誰かが見たい場合は投稿できます。