power shell 删除应用
2021/10/1 7:42:59
本文主要是介绍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 删除应用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-20测试人员都是画画大神,让我看看谁还不会用代码图?
- 2024-05-20年薪百万的程序员都在用的摸鱼方式……
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了