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;
}
}

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

最新文章

  1. BZOJ 3238: [Ahoi2013]差异 [后缀数组 单调栈]
  2. Java基础--serialVersionUID
  3. YII2项目常用技能知识总结
  4. python json学习之路2-认识python种的json模块
  5. SSH Secure Shell Client的windows客户端样式设置
  6. Windows2008 R2下,DCOM配置里的属性灰色不可用的解决方法
  7. 161014、Comet4J介绍及使用(即时推送)
  8. Oracle GoldenGate 11.2 OGG-01168(转)
  9. NSS_01 开始
  10. #include&lt;unistd.h&gt;存在linux中,含有系统服务的函数
  11. &lt;hdu - 1232&gt; 畅通工程 并查集问题 (注意中的细节)
  12. FZU 1502 Letter Deletion(DP)
  13. python制作爬虫爬取京东商品评论教程
  14. mongodb与mysql命令详细对比
  15. 软工个人博客作业Week 1
  16. python+django+uwsgi 搭建环境
  17. 《centos系列》git的安装
  18. Spring框架的事务管理之基于AspectJ的注解方式(重点掌握,最简单的方式)
  19. 我学cocos2d-x (三) Node:一切可视化对象的祖先
  20. day25&lt;多线程+&amp;设计模式&amp;GUI&gt;

热门文章

  1. 一些开源软件的LOGO
  2. go web编程学习记录
  3. Python学习笔记组织文件之将指定目录下的指定格式文件压缩到指定文件夹
  4. Oracle 会话锁死
  5. ubuntu20.04系统openjdk11变更openjdk-8-jdk
  6. fastadmin添加自定义按钮
  7. 35.Linux 性能监控常用命令
  8. Java课后总结2
  9. LaTex【八】latex公式不自动编号
  10. vue axios传值到后端报错问题