【发布时间】:2020-02-07 14:39:00
【问题描述】:
我已将 UWP 应用程序旁加载到我的客户端计算机上。
我现在想卸载程序,但没有管理员权限。
我找到了Remove-AppxPackage,但这需要使用powershell,因此需要一个executionpolicy 设置,这需要管理员访问权限
对于我的 WPF 应用程序,我只会删除包含该应用程序的目录,但对于 UWP 应用程序,我什至不确定要删除什么。
基本上我想以编程方式单击添加和删除程序中的卸载按钮
我确实用代码查看了这个链接How to uninstall application programmatically:
public static string GetUninstallCommandFor(string productDisplayName)
{
RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,RegistryView.Registry64);
string productsRoot = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products";
RegistryKey products = localMachine.OpenSubKey(productsRoot);
string[] productFolders = products.GetSubKeyNames();
foreach (string p in productFolders)
{
RegistryKey installProperties = products.OpenSubKey(p + @"\InstallProperties");
if (installProperties != null)
{
string displayName = (string)installProperties.GetValue("DisplayName");
Debug.WriteLine(displayName);
if ((displayName != null) && (displayName.Contains(productDisplayName)))
{
string uninstallCommand = (string)installProperties.GetValue("UninstallString");
return uninstallCommand;
}
}
}
return "";
}
但这并没有找到我的应用程序 - 即使它位于“应用程序和功能”设置页面中
【问题讨论】:
-
你的意思是 uwp 应用可以自行卸载吗?
-
@NicoZhu-MSFT 不,我想编写一个 c# 程序,可以卸载我已侧载的 UWP 应用程序
-
您可以使用powershell卸载uwp应用,请尝试在您的工具中调用powershell命令。
-
@NicoZhu-MSFT 不幸的是,powershell 需要一个 ExecutionPolicy,如果没有 管理员访问权限,则无法更改
标签: c# uwp uninstallation