共用方式為


PackageManager.RemovePackageAsync 方法

定義

多載

RemovePackageAsync(String)

以異步方式移除目前使用者的 套件 ,並在移除作業上接收進度和狀態消息。 如果使用者未安裝其他套件,則也會移除使用者的相依性套件。

RemovePackageAsync(String, RemovalOptions)

以異步方式移除目前使用者的 套件 ,並在移除作業上接收進度和狀態消息。 如果使用者未安裝其他套件,則也會移除使用者的相依性套件。

RemovePackageAsync(String)

以異步方式移除目前使用者的 套件 ,並在移除作業上接收進度和狀態消息。 如果使用者未安裝其他套件,則也會移除使用者的相依性套件。

public:
 virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ RemovePackageAsync(Platform::String ^ packageFullName) = RemovePackageAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageAsync(winrt::hstring const& packageFullName);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> RemovePackageAsync(string packageFullName);
function removePackageAsync(packageFullName)
Public Function RemovePackageAsync (packageFullName As String) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)

參數

packageFullName
String

Platform::String

winrt::hstring

要移除之封裝識別的字串表示。

傳回

部署要求的狀態。 DeploymentResult 包含部署作業的最終傳回值,完成之後。 DeploymentProgress 可用來取得整個部署作業過程中完成的百分比。

屬性

範例

呼叫 RemovePackageAsync (String) 方法來卸載應用程式套件。 請注意, packageFullName 中的套件完整名稱來自命令行自變數。

RemovePackageAsync (String) 會傳回可用來管理異步操作的物件。 使用 Completed 屬性來設定 委派。 檢查 Status 屬性以判斷部署作業的狀態。 如果狀態為 Error,此範例會呼叫 GetResults 方法來取得其他錯誤資訊。

using Windows.Foundation;
using Windows.Management.Deployment;

[STAThread]
public static int Main(string[] args)
{
    string inputPackageFullName = args[0];
    int returnValue = 0;

    PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

    IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = 
        packageManager.RemovePackageAsync(inputPackageFullName);
    // This event is signaled when the operation completes
    ManualResetEvent opCompletedEvent = new ManualResetEvent(false); 

    // Define the delegate using a statement lambda
    deploymentOperation.Completed = (depProgress, status) => { opCompletedEvent.Set(); };

    // Wait until the operation completes
    opCompletedEvent.WaitOne();

    // Check the status of the operation
    if (deploymentOperation.Status == AsyncStatus.Error)
    {
        DeploymentResult deploymentResult = deploymentOperation.GetResults();
        Console.WriteLine("Error code: {0}", deploymentOperation.ErrorCode);
        Console.WriteLine("Error text: {0}", deploymentResult.ErrorText);
        returnValue = 1;
    }
    else if (deploymentOperation.Status == AsyncStatus.Canceled)
    {
        Console.WriteLine("Removal canceled");
    }
    else if (deploymentOperation.Status == AsyncStatus.Completed)
    {
        Console.WriteLine("Removal succeeded");
    }
    else
    {
        returnValue = 1;
        Console.WriteLine("Removal status unknown");
    }

    return returnValue;
}

另請參閱 C++/WinRT 的 Visual Studio 支援

// main.cpp : In Visual Studio, create a new Windows Console Application (C++/WinRT).
#include "pch.h"

#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Management.Deployment.h>
#include <iostream>

using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Management::Deployment;

int wmain(int /* argc */, wchar_t *argv[], wchar_t * /* envp[] */)
{
    winrt::init_apartment();

    int returnValue{ 0 };

    std::wstring inputPackageFullName{ argv[1] };
    PackageManager packageManager;

    auto deploymentOperation{ packageManager.RemovePackageAsync(inputPackageFullName) };
    deploymentOperation.get();

    // Check the status of the operation
    if (deploymentOperation.Status() == AsyncStatus::Error)
    {
        auto deploymentResult{ deploymentOperation.GetResults() };
        std::wcout << L"Error code: " << deploymentOperation.ErrorCode() << std::endl;
        std::wcout << L"Error text: " << deploymentResult.ErrorText().c_str() << std::endl;
        returnValue = 1;
    }
    else if (deploymentOperation.Status() == AsyncStatus::Canceled)
    {
        std::wcout << L"Removal canceled" << std::endl;
    }
    else if (deploymentOperation.Status() == AsyncStatus::Completed)
    {
        std::wcout << L"Removal succeeded" << std::endl;
    }
    else
    {
        std::wcout << L"Removal status unknown" << std::endl;
        returnValue = 1;
    }
    return returnValue;
}
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Management::Deployment;

int __cdecl main(Platform::Array<String^>^ args)
{
    String^ inputPackageFullName = args[1];
    int returnValue = 0;

    PackageManager^ packageManager = ref new PackageManager();

    auto deploymentOperation = packageManager->RemovePackageAsync(inputPackageFullName);

    DeploymentResult^ deploymentOperationResult;

    // This event is signaled when the operation completes
    opCompletedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    // Define the delegate
    deploymentOperation->Completed = 
        ref new AsyncOperationWithProgressCompletedHandler<DeploymentResult^, DeploymentProgress>(
        [&](IAsyncOperationWithProgress<DeploymentResult^, DeploymentProgress>^ operation, AsyncStatus)
    {
        SetEvent(opCompletedEvent);
    });

    // Wait until the operation completes
    WaitForSingleObject(opCompletedEvent, INFINITE);

    // Check the status of the operation
    if ( deploymentOperation->Status == AsyncStatus::Error )
    {
        auto deploymentResult = deploymentOperation->GetResults();
        wcout << L"Removal Error: " << deploymentOperation->ErrorCode.Value << endl;
        wcout << L"Detailed Error Text: " << deploymentResult->ErrorText->Data() << endl;
        returnValue = 1;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Canceled )
    {
        wcout << L"Removal Canceled" << endl;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Completed )
    {
        wcout << L"Removal succeeded!" << endl;
    }
    else
    {
        wcout << L"Removal status unknown" << endl;
        returnValue = 1;
    }

    return returnValue;
}

備註

若要讓這個方法的呼叫成功,呼叫端必須滿足下列其中一個條件:

  • 呼叫端正在AppContainer (Low IL) 中執行, 具有 packageManagement 受限制的功能。
  • 呼叫端正在以中 IL 或更新版本執行。
  • 呼叫端的發行者符合要移除之套件 (或磁碟區) 的發行者。

如需上述詞彙的描述,以及詳細信息的連結,請參閱 封裝、部署和程式

無法取消此要求。 套件完整名稱是封裝身分識別的替代形式,其較短,適合命名檔案和目錄等物件。 封裝身分識別是由封裝指令清單的 Identity 元素表示。 拿掉套件時,會移除目前使用者的套件,這表示如果其他使用者已安裝套件,封裝承載仍會繼續存在,但目前使用者將無法存取它。 如果沒有其他使用者已安裝指定的套件,則會從 %ProgramFiles%\WindowsApps 目錄移除其承載。 與即將移除之套件相關聯的任何應用程式都會在套件移除過程中自動關閉。

另請參閱

適用於

RemovePackageAsync(String, RemovalOptions)

以異步方式移除目前使用者的 套件 ,並在移除作業上接收進度和狀態消息。 如果使用者未安裝其他套件,則也會移除使用者的相依性套件。

public:
 virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ RemovePackageAsync(Platform::String ^ packageFullName, RemovalOptions removalOptions) = RemovePackageAsync;
/// [Windows.Foundation.Metadata.Overload("RemovePackageWithOptionsAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageAsync(winrt::hstring const& packageFullName, RemovalOptions const& removalOptions);
[Windows.Foundation.Metadata.Overload("RemovePackageWithOptionsAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> RemovePackageAsync(string packageFullName, RemovalOptions removalOptions);
function removePackageAsync(packageFullName, removalOptions)
Public Function RemovePackageAsync (packageFullName As String, removalOptions As RemovalOptions) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)

參數

packageFullName
String

Platform::String

winrt::hstring

要移除之封裝識別的字串表示。

removalOptions
RemovalOptions

可修改移除作業的 RemovalOptions 型別值。

傳回

接收實作 IAsyncOperationWithProgress 介面之物件地址的指標。

屬性

備註

若要讓這個方法的呼叫成功,呼叫端必須滿足下列其中一個條件:

  • 呼叫端正在AppContainer (Low IL) 中執行, 具有 packageManagement 受限制的功能。
  • 呼叫端正在以中 IL 或更新版本執行。
  • 呼叫端的發行者符合要移除之套件 (或磁碟區) 的發行者。

如需上述詞彙的描述,以及詳細信息的連結,請參閱 封裝、部署和程式

另請參閱

適用於