public static UwpAppInfo SearchUwpAppByName(string appName)
{
UwpAppInfo app = null;
try
{
string resultOutput;
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = string.Format("/C powershell Get-AppxPackage -Name \"{0}\"", appName);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
resultOutput = proc.StandardOutput.ReadToEnd();
appName = appName.Replace("*", "");
if (resultOutput.Contains(appName))
{
app = new UwpAppInfo();
string[] appInfo = resultOutput.Replace("\r\n", ":").Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
app.Name = GetAppVauleByItemName(appInfo, "Name");
app.Arch = GetAppVauleByItemName(appInfo, "Architecture");
app.Version = GetAppVauleByItemName(appInfo, "Version");
app.PackageFullName = GetAppVauleByItemName(appInfo, "PackageFullName");
app.PackageFamilyName = GetAppVauleByItemName(appInfo, "PackageFamilyName");
app.InstallLocation = GetAppVauleByItemName(appInfo, "InstallLocation");
app.PublisherId = GetAppVauleByItemName(appInfo, "PublisherId");
}
proc.Close();
return app;
}
catch (Exception ex)
{
Logger.Instance.WriteLog("SearchUwpAppByName UWP excepiton:" + ex.Message, LogType.Error);
return null;
}
} public static void Uninstallapp()
{
string LenovoUtilityAppIdName = "E0469640.LenovoUtility_5grkq8ppsgwt4(app名吧大概)";
UwpAppInfo comp = SearchUwpAppByName(LenovoUtilityAppIdName);
if (comp != null)
{
UninstallUwpApp(comp.PackageFullName);
}
} public static void RunPowershellCmdlet(string cmdlet)
{
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipe = runspace.CreatePipeline();
pipe.Commands.AddScript(cmdlet);
pipe.Invoke();
runspace.Close();
} public static bool UninstallUwpApp(string appFullName)
{
string packageCachePath = @"C:\ProgramData\Packages\E046963F.LenovoCompanion_k1h2ywk1493x8";
int timeOut = 0;
try
{
RunPowershellCmdlet("Remove-AppxPackage " + appFullName.Trim());
/*
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = string.Format("/C powershell Remove-AppxPackage \"{0}\"", appFullName);
proc.StartInfo.UseShellExecute = true;
proc.Start();
proc.WaitForExit();
proc.Close();
*/
while (Directory.Exists(packageCachePath) && timeOut < 10)
{
Directory.Delete(packageCachePath, true);
Thread.Sleep(TimeSpan.FromSeconds(1));
timeOut++;
}(好像是用来验证的) return true;
}
catch (Exception ex)
{
Logger.Instance.WriteLog("Uninstall UWP excepiton:" + ex.Message, LogType.Error);
return false;
}
}

很难看懂 不推荐看不懂的人用

power shell 删除应用的更多相关文章

  1. Windows Power Shell

    Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能. 它引入了许多非常有用的新概念,从而进一步扩展了您在 W ...

  2. SQL Server自动化运维系列——监控性能指标脚本(Power Shell)

    需求描述 一般在生产环境中,有时候需要自动的检测指标值状态,如果发生异常,需要提前预警的,比如发邮件告知,本篇就介绍如果通过Power shell实现状态值监控 监控值范围 根据经验,作为DBA一般需 ...

  3. SQL Server自动化运维系列——监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  4. SQL Server自动化运维系列——监控跑批Job运行状态(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在上一篇文章中已经分析了SQL SERVER中关于邮 ...

  5. SQL Server自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  6. Windows Azure系列-- 配置Azure Power Shell

    1.下载Azure Power shell https://azure.microsoft.com/en-us/documentation/articles/powershell-install-co ...

  7. Power shell 重启IIS

    最近根据项目需要写了一段power shell的代码 ,主要功能是批量重启IIS 具体的 Power shell 服务如下: write-output 'Restarting IIS servers ...

  8. win7 升级Power Shell到4.0

    因为用到EntityFrameworkCore ,想使用scaffold 来生成models. 提示我power Shell 2.0不支持命令,然后需要升级PS. PS  win7 升级文件下载地址是 ...

  9. Windows Power Shell简介

    Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能. 它引入了许多非常有用的新概念,从而进一步扩展了您在 W ...

  10. Power Shell 学习笔记

    Powershell 是运行在windows机器上实现系统和应用程序管理自动化的命令行脚本环境. 桌面右击任务栏开始图标,打开控制台对话窗: Windows PowerShell ISE 应用程序的文 ...

随机推荐

  1. DOS批处理命令,自动获取本机系统及硬件配置信息

    可以配合域策略自动下发执行, 批量收集域内电脑配置; 手动执行亦可; 如下保存成.bat批处理文件执行即可. /*&cls&echo off&cd /d "%~dp0 ...

  2. iphone tabbar问题

    适配新款苹果底部tabbar,网上找了代码,不能用.翻出苹果各型号尺寸发现找的代码稍微有点问题.自己改了下. 关键的判断在于window.screen.height > 800这是区分带tabb ...

  3. 如何把高德地图搜索商家电话资料导出成excel里?

    有很多人问我地图商家结果采集怎么做? 怎么样能够快速的把高德地图左边的搜索列表里的商家地图,电话,导出到EXCEL里. 如何快速地将高德地图里的商家电话资料导出EXCEL? 操作步骤: 1. 选择你要 ...

  4. spring-cloud-alibaba-dubbo踩坑记

    在https://start.aliyun.com/bootstrap.html下载了示例程序,用的版本如下: spring-boot:2.3.7.RELEASE spring-cloud-aliba ...

  5. SSH 秘钥登入

    1.打开权限 vim /etc/ssh/sshd_config   去掉  PubkeyAuthentication yes  一行的#  2.重启ssh服务 systemctl restart ss ...

  6. Redis设计实现-学习笔记

    最近在准备面试,问到redis相关知识,只能说个皮毛,说的既不深入也不全面,所以抓紧突击一下,先学<redis设计与实现>. 选择看书的原因是: 书中全面深入,且能出书一定十分用心: 搜博 ...

  7. 19 request请求数据大全

    1 request.path_info # 获取当前用户请求的url # http://127.0.0.1:8000/customer/list/ ----> /customer/list/ # ...

  8. 通过ref调取子组件方法

    子 async update(res){ //this.$refs.child.animates(); this.userform = res; }, 主 <DetailEdit @detail ...

  9. 对synchronized的理解和Spring为什么是单例的

    只有真正理解了Java中对象是什么,才能理解这个关键字是什么意思 字面解释 Java Guide中如此解释: synchronized 关键字解决的是多个线程之间访问资源的同步性,synchroniz ...

  10. gdb 脚本 简单理解

    1. gdb 脚本的语法简介: 摘录博客:https://blog.csdn.net/hejinjing_tom_com/article/details/50350865 1]   # 为脚本注释命令 ...