2013-07-25 131 views
5

我目前正在編寫一個腳本,其中涉及到一些WES 7設備上安裝的程序的卸載。我需要卸載的一個應用程序(VMware Horizo​​n View Client)要求重新啓動。當這是腳本的一部分時,它似乎接受默認按鈕(是)並繼續重新啓動設備。因此腳本失敗。Powershell卸載腳本 - 真的很頭疼

我真的很感謝你的幫助,以防止發生這種重新啓動。

僅供參考:此腳本通過管理工具下發並在目標上以高架方式運行。

這是我的腳本:

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 

我將非常感謝如何防止通過腳本重啓中途一些幫助。

回答

10

我強烈建議不要使用Win32_Product。每次調用Win32_Product時,都會對每個安裝進行軟件一致性檢查。這不僅會讓事情變得非常緩慢,而且如果發現有問題,也可能會引發軟件修復。

http://gregramsey.net/2012/02/20/win32_product-is-evil/

而是進入註冊表,並調用卸載字符串。

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

您可以使用MSIEXEC的norestart更新日誌文件標誌,以儘量避免重新啓動。

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