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 应用程序的文 ...
随机推荐
- Windows下使用Fortran读取HDF5文件
需要用Fortran读取HDF5格式的GPM IMERG卫星降水文件,在已经安装HDF5库(参见VS2019+ Intel Fortran (oneAPI)+HDF5库的安装+测试 - chinago ...
- java 基本知识点
多线程 加载器 数据结构 内存模型 gc算法
- 04jsp(1)
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...
- SourceInsight中inc文件中的符号不能同步问题
解决方法: 打开Options->Preferences->Syntax Formatting->File Types,然后选中对应的开发语言,如C/C++ Source File, ...
- 《深入剖析Nginx》 笔记
nginx的编译安装使用Linux下通用的三板斧即可:./configure make make install 查看帮助选项./configure --help 禁用编译器优化方法一:CFLAGS= ...
- slam面试题
2022最新SLAM面试题汇总(持续更新中 https://blog.csdn.net/soaring_casia/article/details/125898830 candy边缘算子 http ...
- SQL Server【提高】碎片
碎片 当对索引所在的基础数据表进行增删改时,若存储的数据进行了不适当的跨页(SQL Server中存储的最小单位是页,页是不可再分的),就会导致索引碎片的产生. 外部碎片 插入的数据使页与页之间造成断 ...
- maven 通用pom.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http:// ...
- ICPC2020上海B - Mine Sweeper II
思维 [B-Mine Sweeper II_第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)(重现赛)@hzy0227 (nowcoder.com)](https://codeforc ...
- Es6中模块引入的相关内容
注意:AMD规范和commonJS规范 1.相同点:都是为了模块化. 2.不同点:AMD规范则是非同步加载模块,允许指定回调函数.CommonJS规范加载模块是同步的,也就是说,只有加载完成,才能执行 ...