Category filter
Script to restart Google Chrome on Windows devices
Google Chrome is an essential part of all our work lives. But the zillion tabs we keep open for days on end can harm the device, making it slower, less efficient and prone to security threats, which is why IT admins need to restart Chrome on their managed devices from time to time. A restart could also be necessary in case of a Chrome update or as part of a troubleshoot. With the help of Hexnode UEM’s Execute Custom Script action, IT admins can deploy the script given below to restart Google Chrome remotely on Windows devices.
PowerShell script to restart Google Chrome:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
$script = @" Get-Process -Name "chrome" -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 5 Start-Process -FilePath "C:\Program Files\Google\Chrome\Application\chrome.exe" -WorkingDirectory "C:\Program Files\Google\Chrome\Application" "@ try{ #determining the current logged in user $currentLoggedInuser="" $signedInUsers=get-wmiobject win32_process | where-object {$_.processname -eq "explorer.exe"} | Foreach ({$_.getowner().user}) foreach($user in $signedInUsers) { $isactive = C:\windows\system32\qwinsta.exe $user if($isactive -like "* Active*") { $currentLoggedInuser = $user break } } if($currentLoggedInuser -eq "") { Write-Host "cannot find any logged in user, so skipping script execution`nTo execute this script, atleast one user must be logged-in to the device" } else { Write-Host "scheduling task for user: ",$currentLoggedInuser Write-Host "provided script:`n", $script Set-Content -Path C:\Hexnode\Logs\Script.ps1 -Value $script #unregistering UninstallDesktopAppTask task from task scheduler (if we have already registered using script execution) try { $a=Unregister-ScheduledTask -TaskName "RestartChromeApp" -Confirm:$false -ErrorAction:Ignore } catch { Write-Host "error while unregistering sheduletask-->",$_.Exception.Message } #scheduling task $actions = (New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -File C:\Hexnode\Logs\Script.ps1") $principal = New-ScheduledTaskPrincipal -UserId $currentLoggedInuser -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -WakeToRun -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Hidden -AllowStartIfOnBatteries -Priority 0 -StartWhenAvailable $task = New-ScheduledTask -Action $actions -Principal $principal -Settings $settings $reg= Register-ScheduledTask 'RestartChromeApp' -InputObject $task Start-ScheduledTask -TaskName "RestartChromeApp" -Verbose } } catch { Write-Host "Exception inside running script-->",$_.Exception.Message } |
The script uses Task Scheduler to automate the restart. The file path following –FilePath
and –WorkingDirectory
has to be modified according to the location of the app on the devices.