Restart Explorer

From psadt | Evergreen Application Management
Jump to navigation Jump to search

About

Powershell.png

PowerShell function to monitor explorer.exe and restart it in the user context if it is killed, as can happen during some application uninstalls.


Function

# Restart Explorer if killed due to shell integration (only if machine is logged in).
$Username=(Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Username ) -Split "\\"
If ($Username[1] -ne "System" -AND $Username[1] -ne $env:COMPUTERNAME+'$' -AND $Username[1] -ne $null )
	{
	If (-NOT(Get-Process -Name 'Explorer' -ErrorAction SilentlyContinue))
		{Execute-ProcessAsUser -Path 'Explorer.exe' -ErrorAction SilentlyContinue}
	}