2

When I had Windows 7, I used this thread to add a functionality that lets me right click the desktop and click to find the background that is currently being used. However, ever since updating to Windows 8.1 I have not been able to add the same functionality by using the same technique.

I've navigated in regedit to HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper, which gives me the following path: C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper. When I put this path into FileExplorer it asks me to open the image using one of my image editors/viewers. When I do, it is the correct image, but that's not what I'm looking for. I'm looking for the actual image's filepath so that I can delete the original photo. TranscodedWallpaper seems to update with each background change.

I know for a fact that all the backgrounds are found in D:\Users\MyUser\Pictures\Backgrounds (Windows is on the C drive), but there are about 1.4k images so looking through them each time for the image would be too much of a hassle.

So, how can I add this functionality back to my setup? At the very least, how can I get the file path of the current background image?

0
2

Although this is now an old question, I thought it still worth making the following post. Until recently I’ve been running Windows 7 and a few years ago as an exercise had written a simple program running with a system tray icon to discover the path to the current desktop background image. When I upgraded to Windows 10 this no longer worked of course, so I went looking and found Ramesh Srinivasan's blog and John Dangerbrooks' scripts. As a result, I’ve updated my program to work for Windows 8 and beyond and to work for different images for multi-monitor environments, while also maintaining backwards compatibility with Windows 7.

I’m sharing this program with the wider community in case anyone else likes the idea of having this as a system tray tool. It is written in C# and requires .Net framework v4, and is available as separate .zip files for x86 (32-bit) and x64 (64-bit) environments. There’s no installer, it’s just a simple executable with a readme file. Personally I start it automatically using the HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key, but I leave that detail to you. More details are in the readme.

The zip files are located here https://onedrive.live.com/redir?resid=B2EA2CF6592EC937!839&authkey=!AMNZgrGbt9raflQ&ithint=folder%2czip. (The old short link http://1drv.ms/1OoQRti appears not to work any more - has Microsoft removed the ability to generate short links for OneDrive folders?)

2
  • Do you have any idea how this could be modified to handle multiple monitors with different backgrounds? – Zach Saucier Dec 1 '15 at 21:03
  • 1
    The program should work for different backgrounds on multiple monitors. However, there is a restriction on the length of the tooltip text of 63 characters so I chose to only display one image path in the tooltip. If however you right click on the system tray icon, you should see the image paths for each of your monitors displayed in the popup menu and have the ability to select one of these such that the other menu items operate on the selected image path. It isn't perfect but I find it handy. – Dunc Dec 3 '15 at 11:47
3

I have found a website that has a script you can download and run on your machine, it gives you a popup for the location and name of the image running on your background. The reason you can't get your Windows 7 tweak to work is because the information is stored differently in the registry in Windows 8. In Windows 7 it's in plain text (plain English) and in Windows 8 it is stored in raw binary

01010100 01101000 01100101 00100000 01100001 01101110 01110011 01110111 01100101
01110010 01110011 00100000 01110100 01101111 00100000 01100001 01101100 01101100
00100000 01101111 01100110 00100000 01111001 01101111 01110101 01110010 00100000
01110001 01110101 01100101 01110011 01110100 01101001 01101111 01101110 01110011
00100000 01100001 01110010 01100101 00100000 01101111 01101110 00100000 01000111
01101111 01101111 01100111 01101100 01100101 00101110 01100011 01101111 01101101
00101110 00101110 00101110

You can find the script here

0
1

The link that Reeves posted led to creating a .ps1 file with this script inside of it. Running this new file in Windows Power Shell did open File Explorer pointing to the background image. I had to change the ExecutionPolicy to allow PS to run .ps1 files.

However, opening PS each time and then running command was more of a hassle than I wanted, so I read this SO post and made a shortcut on my desktop that had a target of

powershell.exe -command "& 'C:\A path to the new ps1 file\MyScript.ps1'"

Here's a copy of the script used in the .ps1 case the link goes down:

Try 
{
  # Get script name
  $ScriptName=(Get-Item $PSCommandPath).Name

  # Load Windows Forms and initialize visual styles
  # Not needed for Windows 8. But I still don't know whether it is running on Windows 8.
  [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  [System.Windows.Forms.Application]::EnableVisualStyles()

  # Check Windows verison
  $vers=[System.Environment]::OSVersion.Version
  If (!(($vers.Major -eq 6) -and ($vers.Minor -ge 2) -and ($vers.Minor -le 3))) {
    $result=[System.Windows.Forms.MessageBox]::Show("This operating system is not supported. This script only supports Windows NT 6.2 or 6.3. (i.e. Windows 8, Windows Server 2012, Windows 8.1 or Windows Server 2012 R2). You seem to be running:`r`r"+[System.Environment]::OSVersion.VersionString, "Script", "OK", "Error");
    break;
  }

  # Initialize counters
  $Path_Start_Delta=24  #The offset at which the image path starts
  $Path_End_Delta=-1    #The offset at which the image path ends... is still unknown

  # First, access Windows Registry and get the property containing wallpaper path
  try {
    $TranscodedImageCache=(Get-ItemProperty 'HKCU:\Control Panel\Desktop' TranscodedImageCache -ErrorAction Stop).TranscodedImageCache
  }
  catch [System.Management.Automation.ItemNotFoundException],[System.Management.Automation.PSArgumentException]  {
    $result=[System.Windows.Forms.MessageBox]::Show("Windows does not seem to be holding a record of a wallpaper at this time.`r`r"+$Error[0].Exception.Message,"Script","OK","Error");
    break;
  }

  # Decode the property containing the path
  # First, let's assume the path ends at the last byte of $TranscodedImageCache
  $Path_End_Delta=$TranscodedImageCache.length-1

  # A sequence of 0x00 0x00 marks the end of string. Find it.
  # The array that we are searching contains a UTF-16 string. Each character is a little-endian WORD,
  # so we can search the array's even indexes only.
  for ($i = $Path_Start_Delta; $i -lt ($TranscodedImageCache.length); $i += 2) {
    if ($TranscodedImageCache[($i+2)..($i+3)] -eq 0) {
      $Path_End_Delta=$i + 1;
      Break;
    }
  }

  # Convert the bytes holding the wallpaper path to a Unicode string
  $UnicodeObject=New-Object System.Text.UnicodeEncoding
  $WallpaperSource=$UnicodeObject.GetString($TranscodedImageCache[$Path_Start_Delta..$Path_End_Delta]);


  # Test item's existence
  Get-Item $WallpaperSource -Force -ErrorAction Stop | Out-Null


  # Wallpaper should by now have been found.
  # Present it to the user. If he so chooses, launch Explorer to take him were wallpaper is.
  $result=[System.Windows.Forms.MessageBox]::Show("Wallpaper location: `r$WallpaperSource`r`rLaunch Explorer?", "Script", "YesNo", "Asterisk");
  if ($result -eq "Yes")
  {
      Start-Process explorer.exe -ArgumentList "/select,`"$WallpaperSource`""
  }
}
Catch
{
  $result=[System.Windows.Forms.MessageBox]::Show("Error!`r`r"+$Error[0], "Script", "OK", "Error");
  break;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.