在我的情况下,我有一个很大的图像文件夹,我的墙纸会循环通过这些图像。一段时间后,我感到有些无聊,想要删除它们,或者有时我只是想知道映像名称是什么,因为它可以包含映像的描述。
我根据以上反馈构建了2个脚本-一个用于获取当前图像路径,另一个用于删除它。仅在Windows 10上对此进行了测试。
获取图像路径(getwallpaper.ps1)
$bytes=(New-Object -ComObject WScript.Shell).RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\TranscodedImageCache")
$wallpaperpath=[System.Text.Encoding]::Unicode.GetString($bytes[24..($bytes.length-1)])
$wallpaperpath=$wallpaperpath.substring(0, $wallpaperpath.IndexOf("jpg", 0, $wallpaperpath.Length)+3)
write-output $wallpaperpath
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
删除图像(deletewallpaper.ps1)
$bytes=(New-Object -ComObject WScript.Shell).RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\TranscodedImageCache")
$wallpaperpath=[System.Text.Encoding]::Unicode.GetString($bytes[24..($bytes.length-1)])
$wallpaperpath=$wallpaperpath.substring(0, $wallpaperpath.IndexOf("jpg", 0, $wallpaperpath.Length)+3)
write-output $wallpaperpath
Write-Host -NoNewLine 'Delete the file (y=yes)?'
$KeyOption = 'Y','N'
while ($KeyOption -notcontains $KeyPress.Character) {
$KeyPress = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
if($KeyPress.Character -eq 'y') { Remove-Item $wallpaperpath }
}
Write-Host
[Environment]::Exit(0)