Add lock_dir function that delete GWX folder
This commit is contained in:
parent
34a6fb45a0
commit
eecf96cf8b
1 changed files with 20 additions and 9 deletions
|
@ -22,6 +22,10 @@ $sheduledTasks=(
|
|||
@{name = "refreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"}
|
||||
)
|
||||
|
||||
$gwx_dirs=(
|
||||
"$env:windir\system32\GWX",
|
||||
)
|
||||
|
||||
# You need to modify this variable whith administrator group name
|
||||
# Here for French Windows this is Administrateurs
|
||||
$adminGroup="Administrateurs"
|
||||
|
@ -77,7 +81,7 @@ function hide_update() {
|
|||
$found = 1
|
||||
if (!$update.IsHidden) {
|
||||
$update.IsHidden = "True"
|
||||
Write-Host -ForegroundColor green "Hi dden"
|
||||
Write-Host -ForegroundColor green "Hidden"
|
||||
}
|
||||
else {
|
||||
Write-Host -ForegroundColor Yellow "Already hidden"
|
||||
|
@ -87,24 +91,31 @@ function hide_update() {
|
|||
if (!$found){ Write-Host -ForegroundColor Red "Not found" }
|
||||
}
|
||||
}
|
||||
#Remove GWX Files (test)
|
||||
function lock_dir {
|
||||
param([string]$dir)
|
||||
Write-Host -ForegroundColor white "removing $dir content ... "
|
||||
takeown /F "$dir" /R /D $yes 2>&1 | Out-Null
|
||||
icacls "$dir" /C /grant $adminGroup":F" /T 2>&1 | Out-Null
|
||||
Try{ Remove-Item $dir\* -Force -Recurse -ErrorAction SilentlyContinue}
|
||||
Catch {Write-Host -ForegroundColor Red "Some files can't be deleted."}
|
||||
}
|
||||
|
||||
Write-Host -Nonewline -ForegroundColor white "Searching for GWX process ... "
|
||||
if (Get-Process -name GWX -ErrorAction SilentlyContinue) {
|
||||
Write-Host -ForegroundColor DarkGreen -NoNewLine "Running "
|
||||
Write-Host -Nonewline -ForegroundColor white "removing ... "
|
||||
Write-Host -ForegroundColor white "removing ... "
|
||||
Try {Stop-Process -name GWX -Force -ErrorAction SilentlyContinue}
|
||||
Catch { Write-Host -ForegroundColor Red "Error"}
|
||||
}
|
||||
else { Write-Host -ForegroundColor Yellow ("Not running")}
|
||||
|
||||
#Remove GWX Files (test)
|
||||
takeown /F "$env:WINDIR\System32\GWX" /R /D $yes 2>&1 | Out-Null
|
||||
icacls "$env:WINDIR\System32\GWX" /C /grant $adminGroup":F" /T 2>&1 | Out-Null
|
||||
Try{ Remove-Item $env:WINDIR\System32\GWX\* -Force -Recurse -ErrorAction SilentlyContinue}
|
||||
Catch {Write-Host -ForegroundColor Red "Some files can't be deleted."}
|
||||
#lock GWX directory
|
||||
icacls "$env:WINDIR\System32\GWX" /deny Everyone:(CI)(OI)F 2>&1 | Out-Null
|
||||
Write-Host -ForegroundColor white "`nRemoving and locking GWX folders ... "
|
||||
$gwx_dirs | ForEach {
|
||||
lock_dir $_
|
||||
}
|
||||
|
||||
Write-Host -ForegroundColor white "`nRemoving and locking GWX folders ... "
|
||||
|
||||
Foreach($kbID in $kbIDs){
|
||||
$kbNum = $kbID.Replace("KB","")
|
||||
|
|
Reference in a new issue