mirror of
https://github.com/zoicware/RemoveWindowsAI.git
synced 2026-02-06 05:36:54 +01:00
fix temp dir bug when user has space in username
This commit is contained in:
@@ -316,6 +316,8 @@ else {
|
|||||||
$Global:backup = 0
|
$Global:backup = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Global:tempDir = ([System.IO.Path]::GetTempPath())
|
||||||
|
|
||||||
#=====================================================================================
|
#=====================================================================================
|
||||||
|
|
||||||
function Add-LogInfo {
|
function Add-LogInfo {
|
||||||
@@ -842,7 +844,7 @@ Windows Registry Editor Version 5.00
|
|||||||
'@
|
'@
|
||||||
}
|
}
|
||||||
|
|
||||||
$tempDir = ([System.IO.Path]::GetTempPath())
|
|
||||||
New-Item "$($tempDir)DisableAIPhotos.reg" -Value $regContent -Force | Out-Null
|
New-Item "$($tempDir)DisableAIPhotos.reg" -Value $regContent -Force | Out-Null
|
||||||
regedit.exe /s "$($tempDir)DisableAIPhotos.reg"
|
regedit.exe /s "$($tempDir)DisableAIPhotos.reg"
|
||||||
Start-Sleep 1
|
Start-Sleep 1
|
||||||
@@ -862,6 +864,7 @@ Windows Registry Editor Version 5.00
|
|||||||
|
|
||||||
|
|
||||||
function Install-NOAIPackage {
|
function Install-NOAIPackage {
|
||||||
|
|
||||||
if (!$revert) {
|
if (!$revert) {
|
||||||
$package = Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*zoicware*' }
|
$package = Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*zoicware*' }
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
@@ -892,7 +895,7 @@ function Install-NOAIPackage {
|
|||||||
Write-Status -msg 'Downloading RemoveWindowsAI Package From Github...'
|
Write-Status -msg 'Downloading RemoveWindowsAI Package From Github...'
|
||||||
$ProgressPreference = 'SilentlyContinue'
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
try {
|
try {
|
||||||
Invoke-WebRequest -Uri "https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -OutFile "$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -UseBasicParsing -ErrorAction Stop
|
Invoke-WebRequest -Uri "https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -OutFile "$($tempDir)ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -UseBasicParsing -ErrorAction Stop
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Status -msg "Unable to Download Package at: https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -errorOutput
|
Write-Status -msg "Unable to Download Package at: https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -errorOutput
|
||||||
@@ -901,10 +904,10 @@ function Install-NOAIPackage {
|
|||||||
|
|
||||||
Write-Status -msg 'Installing RemoveWindowsAI Package...'
|
Write-Status -msg 'Installing RemoveWindowsAI Package...'
|
||||||
try {
|
try {
|
||||||
Add-WindowsPackage -Online -PackagePath "$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop >$null
|
Add-WindowsPackage -Online -PackagePath "$($tempDir)ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop >$null
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
dism.exe /Online /Add-Package /PackagePath:"$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck >$null
|
dism.exe /Online /Add-Package /PackagePath:"$($tempDir)ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck >$null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1062,7 +1065,8 @@ function Download-AppxPackage {
|
|||||||
$downloadFolder = "$outputDir\$PackageFamilyName"
|
$downloadFolder = "$outputDir\$PackageFamilyName"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$downloadFolder = Join-Path $env:TEMP $PackageFamilyName
|
|
||||||
|
$downloadFolder = Join-Path $tempDir $PackageFamilyName
|
||||||
if (!(Test-Path $downloadFolder -PathType Container)) {
|
if (!(Test-Path $downloadFolder -PathType Container)) {
|
||||||
New-Item $downloadFolder -ItemType Directory -Force | Out-Null
|
New-Item $downloadFolder -ItemType Directory -Force | Out-Null
|
||||||
}
|
}
|
||||||
@@ -1229,8 +1233,8 @@ function Remove-AI-Appx-Packages {
|
|||||||
#to make this part faster make a txt file in temp with chunck of removal
|
#to make this part faster make a txt file in temp with chunck of removal
|
||||||
#code and then just run that from run
|
#code and then just run that from run
|
||||||
#trusted function due to the design of having it hidden from the user
|
#trusted function due to the design of having it hidden from the user
|
||||||
|
|
||||||
$packageRemovalPath = "$env:TEMP\aiPackageRemoval.ps1"
|
$packageRemovalPath = "$($tempDir)aiPackageRemoval.ps1"
|
||||||
if (!(test-path $packageRemovalPath)) {
|
if (!(test-path $packageRemovalPath)) {
|
||||||
New-Item $packageRemovalPath -Force | Out-Null
|
New-Item $packageRemovalPath -Force | Out-Null
|
||||||
}
|
}
|
||||||
@@ -1452,7 +1456,7 @@ foreach ($choice in $aipackages) {
|
|||||||
|
|
||||||
|
|
||||||
Write-Status -msg 'Removing AI Appx Packages...'
|
Write-Status -msg 'Removing AI Appx Packages...'
|
||||||
$command = "&$env:TEMP\aiPackageRemoval.ps1"
|
$command = "&`"$($tempDir)aiPackageRemoval.ps1`""
|
||||||
Run-Trusted -command $command -psversion $psversion
|
Run-Trusted -command $command -psversion $psversion
|
||||||
|
|
||||||
#check packages removal
|
#check packages removal
|
||||||
@@ -1468,7 +1472,7 @@ foreach ($choice in $aipackages) {
|
|||||||
$Global:logInfo.Result = "Found Packages: $packages"
|
$Global:logInfo.Result = "Found Packages: $packages"
|
||||||
Add-LogInfo -logPath $logPath -info $Global:logInfo
|
Add-LogInfo -logPath $logPath -info $Global:logInfo
|
||||||
}
|
}
|
||||||
$command = "&$env:TEMP\aiPackageRemoval.ps1"
|
$command = "&`"$($tempDir)aiPackageRemoval.ps1`""
|
||||||
Run-Trusted -command $command -psversion $psversion
|
Run-Trusted -command $command -psversion $psversion
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2081,8 +2085,8 @@ function Remove-AI-Files {
|
|||||||
'C:\Windows\WinSxS',
|
'C:\Windows\WinSxS',
|
||||||
'C:\Windows\System32\CatRoot'
|
'C:\Windows\System32\CatRoot'
|
||||||
)
|
)
|
||||||
|
|
||||||
New-Item "$env:TEMP\PathsToDelete.txt" -ItemType File -Force | Out-Null
|
New-Item "$($tempDir)PathsToDelete.txt" -ItemType File -Force | Out-Null
|
||||||
foreach ($keyword in $aiKeyWords) {
|
foreach ($keyword in $aiKeyWords) {
|
||||||
foreach ($location in $regLocations) {
|
foreach ($location in $regLocations) {
|
||||||
Get-ChildItem $location -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -like "*$keyword*" } | ForEach-Object {
|
Get-ChildItem $location -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -like "*$keyword*" } | ForEach-Object {
|
||||||
@@ -2108,12 +2112,12 @@ function Remove-AI-Files {
|
|||||||
$(Test-Path $_.FullName -PathType Container) -eq $true
|
$(Test-Path $_.FullName -PathType Container) -eq $true
|
||||||
} | ForEach-Object {
|
} | ForEach-Object {
|
||||||
#add paths to txt to delete with trusted installer
|
#add paths to txt to delete with trusted installer
|
||||||
Add-Content "$env:TEMP\PathsToDelete.txt" -Value $_.FullName | Out-Null
|
Add-Content "$($tempDir)PathsToDelete.txt" -Value $_.FullName | Out-Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$command = "Get-Content `"`$env:TEMP\PathsToDelete.txt`" | ForEach-Object {Remove-Item `$_ -Force -Recurse -EA 0}"
|
$command = "Get-Content `"$($tempDir)PathsToDelete.txt`" | ForEach-Object {Remove-Item `$_ -Force -Recurse -EA 0}"
|
||||||
Run-Trusted -command $command -psversion $psversion
|
Run-Trusted -command $command -psversion $psversion
|
||||||
Start-Sleep 1
|
Start-Sleep 1
|
||||||
}
|
}
|
||||||
@@ -2254,11 +2258,12 @@ Get-ScheduledTask -TaskName "*Office Actions Server*" -ErrorAction SilentlyConti
|
|||||||
}
|
}
|
||||||
Remove-Item 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Office\Office Actions Server' -Recurse -Force -ErrorAction SilentlyContinue
|
Remove-Item 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Office\Office Actions Server' -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
"@
|
"@
|
||||||
$subScript = "$env:TEMP\RemoveRecallTasks.ps1"
|
|
||||||
New-Item $subScript -Force | Out-Null
|
$subScript = "$($tempDir)RemoveRecallTasks.ps1"
|
||||||
Set-Content $subScript -Value $code -Force
|
New-Item "$subScript" -Force | Out-Null
|
||||||
|
Set-Content "$subScript" -Value $code -Force
|
||||||
|
|
||||||
$command = "&$subScript"
|
$command = "&`"$subScript`""
|
||||||
Run-Trusted -command $command -psversion $psversion
|
Run-Trusted -command $command -psversion $psversion
|
||||||
Start-Sleep 1
|
Start-Sleep 1
|
||||||
|
|
||||||
@@ -2565,8 +2570,9 @@ function install-photoslegacy {
|
|||||||
$appx = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like '*PhotosLegacy*' }
|
$appx = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like '*PhotosLegacy*' }
|
||||||
|
|
||||||
if (!$appx) {
|
if (!$appx) {
|
||||||
Remove-Item "$env:TEMP\Microsoft.PhotosLegacy_8wekyb3d8bbwe*" -Force -Recurse -ErrorAction SilentlyContinue
|
|
||||||
$downloadedfiles = Download-AppxPackage -PackageFamilyName 'Microsoft.PhotosLegacy_8wekyb3d8bbwe' -outputDir "$env:TEMP"
|
Remove-Item "$($tempDir)Microsoft.PhotosLegacy_8wekyb3d8bbwe*" -Force -Recurse -ErrorAction SilentlyContinue
|
||||||
|
$downloadedfiles = Download-AppxPackage -PackageFamilyName 'Microsoft.PhotosLegacy_8wekyb3d8bbwe' -outputDir "$tempDir"
|
||||||
$package = $downloadedfiles | Where-Object { $_ -match '\.appxbundle$' } | Select-Object -First 1
|
$package = $downloadedfiles | Where-Object { $_ -match '\.appxbundle$' } | Select-Object -First 1
|
||||||
$dependencies = $downloadedfiles | Where-Object { $_ -match '\.appx$' }
|
$dependencies = $downloadedfiles | Where-Object { $_ -match '\.appx$' }
|
||||||
if ($package) {
|
if ($package) {
|
||||||
@@ -2597,26 +2603,27 @@ function install-classicapps {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#check if they are already downloaded if not download them
|
#check if they are already downloaded if not download them
|
||||||
if (!(Test-Path "$env:TEMP\ClassicApps")) {
|
|
||||||
|
if (!(Test-Path "$($tempDir)ClassicApps")) {
|
||||||
$ProgressPreference = 'SilentlyContinue'
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
Write-Status -msg 'Downloading Classic Apps Files from Github...'
|
Write-Status -msg 'Downloading Classic Apps Files from Github...'
|
||||||
$url = 'https://github.com/zoicware/RemoveWindowsAI/archive/refs/heads/main.zip'
|
$url = 'https://github.com/zoicware/RemoveWindowsAI/archive/refs/heads/main.zip'
|
||||||
try {
|
try {
|
||||||
Invoke-WebRequest -Uri $url -OutFile "$env:TEMP\main.zip" -ErrorAction Stop
|
Invoke-WebRequest -Uri $url -OutFile "$($tempDir)main.zip" -ErrorAction Stop
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Status -msg 'Unable to Download Github Repo' -errorOutput
|
Write-Status -msg 'Unable to Download Github Repo' -errorOutput
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Expand-Archive -Path "$env:TEMP\main.zip" -DestinationPath $env:TEMP -Force
|
Expand-Archive -Path "$($tempDir)main.zip" -DestinationPath "$tempDir" -Force
|
||||||
$sourceDir = "$env:TEMP\RemoveWindowsAI-main\ClassicApps"
|
$sourceDir = "$($tempDir)RemoveWindowsAI-main\ClassicApps"
|
||||||
$destDir = "$env:TEMP\ClassicApps"
|
$destDir = "$($tempDir)ClassicApps"
|
||||||
Copy-Item -Path $sourceDir -Destination $destDir -Recurse -Force
|
Copy-Item -Path $sourceDir -Destination $destDir -Recurse -Force
|
||||||
Remove-Item "$env:TEMP\RemoveWindowsAI-main" -Recurse -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)RemoveWindowsAI-main" -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
Remove-Item "$env:TEMP\main.zip" -Recurse -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)main.zip" -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
$classicApps = "$env:TEMP\ClassicApps"
|
$classicApps = "$($tempDir)ClassicApps"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3515,19 +3522,19 @@ else {
|
|||||||
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
|
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
|
||||||
#cleanup code
|
#cleanup code
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\aiPackageRemoval.ps1" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)aiPackageRemoval.ps1" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\RemoveRecallTasks.ps1" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)RemoveRecallTasks.ps1" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\PathsToDelete.txt" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)PathsToDelete.txt" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\ZoicwareRemoveWindowsAI-*1.0.0.0.cab" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)ZoicwareRemoveWindowsAI-*1.0.0.0.cab" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
|
|
||||||
@@ -3573,19 +3580,19 @@ else {
|
|||||||
|
|
||||||
#cleanup code
|
#cleanup code
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\aiPackageRemoval.ps1" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)aiPackageRemoval.ps1" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\RemoveRecallTasks.ps1" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)RemoveRecallTasks.ps1" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\PathsToDelete.txt" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)PathsToDelete.txt" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
try {
|
try {
|
||||||
Remove-Item "$env:TEMP\ZoicwareRemoveWindowsAI-*1.0.0.0.cab" -Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tempDir)ZoicwareRemoveWindowsAI-*1.0.0.0.cab" -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user