Windows 7 から Powershell を使用して Windows XP Virtual PC アプリケーションを起動するにはどうすればよいですか?

Windows 7 から Powershell を使用して Windows XP Virtual PC アプリケーションを起動するにはどうすればよいですか?

これは、Windows 7 から起動して Windows XP モードでプログラムを起動するアプリケーションのショートカット ターゲットです。

%SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\VMCPropertyHandler.dll,LaunchVMSal "Windows XP Mode" "||fc9407e9" "wIntegrate"

そのターゲットに対して PS Start-process コマンドが機能しないようです。

私が使用するコード:

Start-Process %SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\VMCPropertyHandler.dll,LaunchVMSal "Windows XP Mode" "||fc9407e9" "wIntegrate"

受け取ったエラーは次のとおりです:

Start-Process : A positional parameter cannot be found that accepts argument 'Windows XP Mode'.
At C:\Users\username.domain\Desktop\rebootpick.ps1:13 char:14
+ Start-Process <<<<  %SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\VMCPropertyHandler.dll,LaunchVMSal "Windows XP Mode" "||fc9407e9" "wIntegrate"
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

Windows 7 の Powershell から Windows XP Mode アプリケーションを実行できた人はいますか?

答え1

これで完了です:

$sysRoot = get-content env:systemroot;
Start-Process $sysRoot\system32\rundll32.exe -ArgumentList "$sysRoot\system32\VMCPropertyHandler.dll,LaunchVMSal `"Windows XP Mode`" `"||fc9407e9`" `"wIntegrate`"";
Remove-Variable sysRoot;

最初のトリック: %systemroot% は PS では機能しないため、PS でその環境変数を取得するには変数 ($sysRoot) を割り当てます。

次のトリックは、RunDLL32 に提供される引数が 1 つだけであること、そしてその引数に引数があることを理解することです。したがって、引数のすべての部分を引用符を使用して 1 つの引数に囲む必要があります。ただし、その引数内の既存の引用符は保持する必要があるため、 でエスケープします`

お役に立てれば幸いです...

関連情報