0

別のバージョンをインストールする前に、リモートコンピューターで次のコマンドを実行して、以前のバージョンの製品をアンインストールしようとしています。これは、MsiExec.exeを使用してアンインストールしています。

Start-Processを呼び出すと、プロセスが実際に実行され、製品がリモートコンピューターにアンインストールされますが、以下の例外がスローされます。製品がまだインストールされておらず、Start-Process行が実行されていない場合、remoteコマンドは例外をスローせずに正常に機能します。(つまり、実際にレジストリを検索し、製品を検出せず、例外をスローせずに-1を返します)この問題は、Start-Processが呼び出された場合にのみ発生します。

これが私のスクリプトコードです...

$UninstallScriptBlock = {
    param ( [string]$InstallerProductName )

    $ErrorActionPreference = "Stop";

    $UninstallRegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    $ProductCode = Get-ChildItem -Path $UninstallRegPath | foreach { if ($_.GetValue("DisplayName") -eq $InstallerProductName) { [System.IO.Path]::GetFileName($_); } }
    if ([string]::IsNullOrEmpty($ProductCode))
    {
        $UninstallRegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
        $ProductCode = Get-ChildItem -Path $UninstallRegPath | foreach { if ($_.GetValue("DisplayName") -eq $InstallerProductName) { [System.IO.Path]::GetFileName($_); } }
    }
    if ([string]::IsNullOrEmpty($ProductCode))
    {
        return -1;
    }

    $Process = Start-Process -Wait -Passthru -FilePath "MsiExec.exe" -ArgumentList "/X", $ProductCode, "/qn";
    return $Process.ExitCode;
}

[int]$UninstallReturnCode = Invoke-Command -ComputerName $Server -ScriptBlock $UninstallScriptBlock -ArgumentList $InstallerProductName -SessionOption (New-PSSessionOption -OperationTimeout 0);

そして、スローされた例外...

Processing data for a remote command failed with the following error message: The I/O operation has been aborted because of either a thread exit or an application request. For more information, see the about_Remote_Troubleshooting Help topic.
At [Undisclosed]
+     [int]$UninstallReturnCode = Invoke-Command -ComputerName $Server -ScriptBloc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: ([UndisclosedServerName]:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName        : [UndisclosedServerName]

そしてフォーマットされたエラー...

ErrorCode                   : 995
TransportMessage            : The I/O operation has been aborted because of either a thread exit or an application request.

ErrorRecord                 : Processing data for a remote command failed with the following error message: The I/O
                              operation has been aborted because of either a thread exit or an application request. For
                              more information, see the about_Remote_Troubleshooting Help topic.
StackTrace                  :
WasThrownFromThrowStatement : False
Message                     : Processing data for a remote command failed with the following error message: The I/O
                              operation has been aborted because of either a thread exit or an application request. For
                              more information, see the about_Remote_Troubleshooting Help topic.
Data                        : {}
InnerException              :
TargetSite                  :
HelpLink                    :
Source                      :
4

1 に答える 1

1

私が見つけた最良の答えは、アンインストールによって IIS がリセットされ、Powershell Remoting 接続が切断されるというものです。

これは私が回避策として行ったことです:

  1. -Wait を Start-Process から削除し、すぐに Powershell Remoting セッションを閉じます。
  2. Powershell Remoting セッションが閉じられたら、Start-Sleep に入れて、アンインストールが完了するのを待ちます (アンインストールにかかる時間を推測し、さらにいくつかのパディングを加えます)。
  3. アンインストールのログ ファイルで、「削除の成功またはエラー ステータス: XXXX」というテキストを確認します。XXXX は、アンインストール プロセスのリターン コードです。
于 2013-03-08T14:56:45.010 に答える