power shell 删除应用
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 删除应用的更多相关文章
- Windows Power Shell
Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能. 它引入了许多非常有用的新概念,从而进一步扩展了您在 W ...
- SQL Server自动化运维系列——监控性能指标脚本(Power Shell)
需求描述 一般在生产环境中,有时候需要自动的检测指标值状态,如果发生异常,需要提前预警的,比如发邮件告知,本篇就介绍如果通过Power shell实现状态值监控 监控值范围 根据经验,作为DBA一般需 ...
- SQL Server自动化运维系列——监控磁盘剩余空间及SQL Server错误日志(Power Shell)
需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...
- SQL Server自动化运维系列——监控跑批Job运行状态(Power Shell)
需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在上一篇文章中已经分析了SQL SERVER中关于邮 ...
- SQL Server自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)
需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...
- Windows Azure系列-- 配置Azure Power Shell
1.下载Azure Power shell https://azure.microsoft.com/en-us/documentation/articles/powershell-install-co ...
- Power shell 重启IIS
最近根据项目需要写了一段power shell的代码 ,主要功能是批量重启IIS 具体的 Power shell 服务如下: write-output 'Restarting IIS servers ...
- win7 升级Power Shell到4.0
因为用到EntityFrameworkCore ,想使用scaffold 来生成models. 提示我power Shell 2.0不支持命令,然后需要升级PS. PS win7 升级文件下载地址是 ...
- Windows Power Shell简介
Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能. 它引入了许多非常有用的新概念,从而进一步扩展了您在 W ...
- Power Shell 学习笔记
Powershell 是运行在windows机器上实现系统和应用程序管理自动化的命令行脚本环境. 桌面右击任务栏开始图标,打开控制台对话窗: Windows PowerShell ISE 应用程序的文 ...
随机推荐
- lua-路径加载lua文件-函数返回值,访问lua文件中的变量
lua文件如下: print("ddhdhh")function login(username,pswd)if username =="ms" and pswd ...
- 10 个常用的 JS 工具库,80% 的项目都在用!
Day.js 一个极简的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持一样, 但体积仅有2KB. npm install dayjs 基本用法 import ...
- js中常用的运算符
1. ?. 链接运算符 特性: 一旦遇到空置就会终止 例子: let name = obj?.name persion.getTip?.() // 没有getTip 方法则不会执行 2. ?? 空值合 ...
- Java 03-基础 堆和栈(另,理解Java内存)
概述: 栈区(STACK)堆区(HEAP) 1.栈中主要存放一些基本类型的变量,且每一个基本数据类型有固定的大小(byte,short,int,long,float,double,boolean,ch ...
- input点击焦点后阴影
input[type=text]:focus { outline: none; border-color: rgba(82, 168, 236, 0.8); box-shadow:inset 0 1p ...
- darkriscv笔记
1 按照默认设置,前4K空间为ROM,后4K空间是RAM.为什么RAM需要初值,初值从哪儿来? 2 指令分类 LUI: AUTPC: JAL: JALR: BCC : BEQ/BGE /BGEU/BL ...
- 串口USART(续二)
通过前面的分析知道,在LPC824中,USART所拥有的配置寄存器有很多,但在一般情况下,如果只是简单地使用收发功能,则只需要使用到配置寄存器CFG.波特率发生器寄存器BRG.中断使能读取和置位寄存器 ...
- 1.win10安装centos虚拟机并设置允许远程
一.下载并安装 打开如下连接,下载VMware和CentOS7镜像安装好虚拟机 http://t.zoukankan.com/onlymate-p-9837651.html这个链接的镜像是7.0的,我 ...
- 061_Apex 异常捕捉
Trigger 中的错误处理 在 Trigger 中,我们可以为进行操作的数据进行验证,类似于验证规则.如果遇到不符合条件的数据,可以通过 addError() 函数来将错误显示给用户,并记录日志. ...
- Ajax JavaScript传参-javascript加载本地文件
get请求需要拼接到url里面 post请求,需要放到send方法里面,后端取值的时候,Ajax用JavaScript传输跟用postman传输,取值方式有些区别,这里做一下详细记录 传参格式{'id ...