Powershell 卸载脚本 - 真的很头疼 [英] Powershell Uninstall Script - Have a real headache

查看:139
本文介绍了Powershell 卸载脚本 - 真的很头疼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个脚本,该脚本涉及卸载安装在 WES 7 设备上的程序.我需要卸载的应用程序之一 (VMware Horizo​​n View Client) 要求重新启动.当这是脚本的一部分时,它似乎接受默认按钮(是)并继续重新启动设备.因此脚本失败.

I am currently writing a script that has involves a number of uninstalls of programs installed on a WES 7 device. One of the applications I need to uninstall (VMware Horizon View Client) asks for a restart. When this is part of the script, it seems to accept the default button (YES) and proceeds to reboot the device. The script therefore fails.

我非常感谢您在如何防止重新启动方面的帮助.

I would really appreciate your help in how to prevent this reboot from taking place.

仅供参考:此脚本通过管理工具向下发送,并在目标上以提升的方式运行.

FYI: This script is sent down via a management tool and is run in an elevated manner on the target.

这是我的脚本:

set-executionpolicy unrestricted
#############################################################
# Un-install unwanted applications
#############################################################
$application = Get-WMIObject Win32_Product -filter "Name='ThinPrint Client Windows 8.6'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='2X Client'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='Adobe Reader X (10.1.4)'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='VMware Horizon View Client'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='VERDE VDI User Tools'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='vWorkspace Connector for Windows'"
$application.Uninstall()

#############################################################
# Remove Internet Explorer Access
#############################################################
dism /online /norestart /Disable-Feature /FeatureName:Internet-Explorer-Optional-x86

#############################################################
# Remove IE Browser LNK from Taskbar
#############################################################
del "C:\Users\User\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Launch Internet Explorer Browser.lnk"

#############################################################
# Make Citrix Receiver the shell
#############################################################
Push-Location
CD 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon'
New-Itemproperty -path .\ -name Shell -Type String -Value 'c:\program files\Citrix\Receiver\receiver.exe'
Pop-Location

set-executionpolicy restricted
# End of Script

我非常感谢有关如何防止脚本中途重启的帮助.

I would very much appreciate some help in how to prevent the reboot half way through the script.

推荐答案

我强烈建议不要使用 Win32_Product.每次调用 Win32_Product 时,它都会对每次安装进行软件一致性检查.这不仅会使运行速度变慢,而且如果发现问题,还可能触发软件修复.

I strongly suggest NOT using Win32_Product. Every time Win32_Product is called it does a software consistency check of each installation. Not only does this make things very slow, it may also trigger a software repair if it finds something wrong.

http://gregramsey.net/2012/02/20/win32_product-是邪恶的/

而是进入注册表并调用卸载字符串.

Instead go into the registry and just call the uninstall string.

http://support.microsoft.com/kb/247501

您可以使用 msiexec 的 norestart 标志来尝试防止重新启动.

You can use msiexec's norestart flag to try to prevent reboots.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa372024(v=vs.85).aspx

这篇关于Powershell 卸载脚本 - 真的很头疼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆