如何從 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 模式應用程式?

答案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 中不起作用,因此我們分配一個變數($sysRoot)來取得 PS 中的環境變數。

下一個技巧是認識到只向 RunDLL32 提供了一個參數,並且該參數還有參數。因此,我們需要使用引號將參數的所有部分括在一個參數中。但我們需要保留該參數中現有的引號,因此我們用 轉義它們`

希望有幫助...

相關內容