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 属性以确定部署操作的状态。 如果状态为 “错误”,则示例调用 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;
}

另请参阅 Visual Studio 对 C++/WinRT 的支持

// 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 (低 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 (低 IL) 中运行, 并且 具有 packageManagement 受限功能。
  • 调用方正在运行的 IL 为中或更高。
  • 调用方发布者与要删除的包 (或卷) 的发布者匹配。

有关上述术语的说明以及指向详细信息的链接,请参阅 打包、部署和处理

另请参阅

适用于