// Name: Move Temp Folder to Default Location // Description: Moves the temp folder from X:/temp back to its default Windows 11 location // Author: s3cr1z import "@johnlindquist/kit" const currentTempPath = "X:/temp" const defaultTempPath = `${process.env.USERPROFILE}\\AppData\\Local\\Temp` // PowerShell script to move temp folder back to default location const powershellScript = ` # Check if running as administrator if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Host "This script requires administrator privileges. Please run as administrator." -ForegroundColor Red exit 1 } Write-Host "Moving temp folder from ${currentTempPath} to default location..." -ForegroundColor Yellow # Check if custom temp folder exists if (Test-Path "${currentTempPath}") { Write-Host "Found temp folder at ${currentTempPath}" -ForegroundColor Green # Create default temp directory if it doesn't exist if (!(Test-Path "${defaultTempPath}")) { New-Item -ItemType Directory -Path "${defaultTempPath}" -Force Write-Host "Created default temp directory: ${defaultTempPath}" -ForegroundColor Green } # Copy contents from custom location to default location Write-Host "Copying files from ${currentTempPath} to ${defaultTempPath}..." -ForegroundColor Yellow try { Get-ChildItem -Path "${currentTempPath}" -Recurse | ForEach-Object { $destPath = $_.FullName.Replace("${currentTempPath}", "${defaultTempPath}") if ($_.PSIsContainer) { if (!(Test-Path $destPath)) { New-Item -ItemType Directory -Path $destPath -Force } } else { Copy-Item $_.FullName -Destination $destPath -Force } } Write-Host "Files copied successfully!" -ForegroundColor Green } catch { Write-Host "Error copying files: $($_.Exception.Message)" -ForegroundColor Red } # Reset environment variables to default Write-Host "Resetting TEMP and TMP environment variables..." -ForegroundColor Yellow # Set user environment variables [Environment]::SetEnvironmentVariable("TEMP", "${defaultTempPath}", "User") [Environment]::SetEnvironmentVariable("TMP", "${defaultTempPath}", "User") # Set system environment variables (requires admin) try { [Environment]::SetEnvironmentVariable("TEMP", "%USERPROFILE%\\AppData\\Local\\Temp", "Machine") [Environment]::SetEnvironmentVariable("TMP", "%USERPROFILE%\\AppData\\Local\\Temp", "Machine") Write-Host "System environment variables updated successfully!" -ForegroundColor Green } catch { Write-Host "Warning: Could not update system environment variables: $($_.Exception.Message)" -ForegroundColor Yellow } # Update registry entries Write-Host "Updating registry entries..." -ForegroundColor Yellow try { Set-ItemProperty -Path "HKCU:\\Environment" -Name "TEMP" -Value "${defaultTempPath}" Set-ItemProperty -Path "HKCU:\\Environment" -Name "TMP" -Value "${defaultTempPath}" Write-Host "Registry updated successfully!" -ForegroundColor Green } catch { Write-Host "Error updating registry: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "Temp folder restoration completed!" -ForegroundColor Green Write-Host "Please restart your computer for all changes to take effect." -ForegroundColor Yellow Write-Host "After restart, you can safely delete the old temp folder at ${currentTempPath}" -ForegroundColor Cyan } else { Write-Host "Custom temp folder not found at ${currentTempPath}" -ForegroundColor Red Write-Host "Current TEMP variable points to: $env:TEMP" -ForegroundColor Cyan } Write-Host "Press any key to continue..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") ` // Save the PowerShell script to a temporary file const scriptPath = tmpPath("move-temp-folder.ps1") await writeFile(scriptPath, powershellScript) const choice = await arg({ placeholder: "Choose how to run the PowerShell script", hint: "This script will move your temp folder back to the default Windows location" }, [ { name: "Run PowerShell Script", description: "Execute the script directly (requires admin privileges)", value: "run" }, { name: "Save Script to Desktop", description: "Save the script to your desktop to run manually", value: "save" }, { name: "View Script Content", description: "View the PowerShell script content in editor", value: "view" } ]) switch (choice) { case "run": await notify("Running PowerShell script...") try { // Run PowerShell as administrator await exec(`powershell -Command "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File \\"${scriptPath}\\"' -Verb RunAs"`) } catch (error) { await div(md(` # Error Running Script The script could not be executed automatically. Please: 1. Open PowerShell as Administrator 2. Navigate to: \`${scriptPath}\` 3. Run: \`Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process\` 4. Run: \`& "${scriptPath}"\` **Error:** ${error.message} `)) } break case "save": const desktopPath = home("Desktop", "move-temp-folder.ps1") await writeFile(desktopPath, powershellScript) await revealFile(desktopPath) await notify("PowerShell script saved to desktop!") break case "view": await editor({ value: powershellScript, language: "powershell", hint: "PowerShell script to move temp folder" }) break }