C# Windows 8 中的墙纸注册表项在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11278707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:14:52  来源:igfitidea点击:

Where's the wallpaper registry key in Windows 8?

c#.net

提问by Peter W.

I'm working on a tool that needs to get the current user's wallpaper path.

我正在开发一个需要获取当前用户壁纸路径的工具。

On Windows 7, I can get that by reading

在 Windows 7 上,我可以通过阅读获得

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource.

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource.

On my Windows 8 installation, that key always has the value

在我的 Windows 8 安装中,该键始终具有值

C:\Users\Peter\AppData\Roaming\Microsoft\Windows Photo Viewer\Windows Photo Viewer Wallpaper.jpg

C:\Users\Peter\AppData\Roaming\Microsoft\Windows Photo Viewer\Windows Photo Viewer Wallpaper.jpg

which is not even the wallpaper that's currently set.

这甚至不是当前设置的壁纸。

Is there any other key I can rely on?

还有其他我可以依赖的钥匙吗?

采纳答案by Zuul

The key you are mentioning isn't the correct one. Sounds to me that you've placed an image as your desktop background from Internet Explorer, and that key was opened to register it.

你提到的关键不是正确的。在我看来,您已经从 Internet Explorer 放置了一个图像作为您的桌面背景,并且该密钥已打开以进行注册。

The correct key to get the desktop background location is:Confirmed on: XP, CE, Vista, 7, 8

获取桌面背景位置的正确键是:Confirmed on: XP, CE, Vista, 7, 8

HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper

Details:

细节:

  • Main key: HKEY_CURRENT_USER
  • Sub key: Control Panel\Desktop
  • Value name: WallPaper
  • Value type: REG_SZ
  • Value data: full path for the image being used as the desktop background
  • 主键:HKEY_CURRENT_USER
  • 子项:控制面板\桌面
  • 值名称:墙纸
  • 值类型:REG_SZ
  • 值数据:用作桌面背景的图像的完整路径


Also, under HKEY_CURRENT_USER\Control Panel\Desktop\you will find other wallpaper related options to apply different styles: Center, Tile, and Stretch.

此外,HKEY_CURRENT_USER\Control Panel\Desktop\您还会在下方找到其他与壁纸相关的选项来应用不同的样式:中心、平铺和拉伸。

HKEY_CURRENT_USER\Control Panel\Desktop\WallpaperStyle
HKEY_CURRENT_USER\Control Panel\Desktop\TileWallpaper

In order to apply the styles use the following guide:

为了应用样式,请使用以下指南:

  1. Center

    WallpaperStyle = 0
    TileWallpaper = 0
    
  2. Tile

    WallpaperStyle = 0
    TileWallpaper = 1
    
  3. Stretch

    WallpaperStyle = 2
    TileWallpaper = 0
    
  1. 中心

    WallpaperStyle = 0
    TileWallpaper = 0
    
  2. WallpaperStyle = 0
    TileWallpaper = 1
    
  3. 拉紧

    WallpaperStyle = 2
    TileWallpaper = 0
    

回答by ReinstateMonica Larry Osterman

You are FAR better off calling SystemParametersInfowith the SPI_SETDESKWALLPAPER option to set the desktop wallpaper. As far as I can tell, registry key you're using is undocumented and thus can change at any time without warning.

您最好使用 SPI_SETDESKWALLPAPER 选项调用SystemParametersInfo来设置桌面墙纸。据我所知,您使用的注册表项没有记录,因此可以随时更改而不会发出警告。

See thisstack overflow question for an example of how to call the SystemParametersInfo with SPI_SETDESKWALLPAPER.

有关如何使用 SPI_SETDESKWALLPAPER 调用 SystemParametersInfo 的示例,请参阅堆栈溢出问题。

回答by Rob

Based heavily on the code available at pinvoke.net, the correct way to retrieve the current users desktop wallpaper is to use the SystemParametersInfofunction. A sample of doing this is as follows:

主要基于pinvoke.net上可用的代码,检索当前用户桌面壁纸的正确方法是使用该SystemParametersInfo功能。执行此操作的示例如下:

using System;
using System.Runtime.InteropServices;

namespace WallpaperPathRetrieval
{
    class Program
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern Int32 SystemParametersInfo(UInt32 action, 
            UInt32 uParam, string vParam, UInt32 winIni);
        private static readonly UInt32 SPI_GETDESKWALLPAPER = 0x73;
        private static uint MAX_PATH = 260;

        static void Main(string[] args)
        {
            string wallpaper = new string('##代码##', (int)MAX_PATH);
            SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaper, 0);

            wallpaper = wallpaper.Substring(0, wallpaper.IndexOf('##代码##'));
        }
    }
}

回答by Ramesh

It's stored in a value named TranscodedImageCache (REG_BINARY). Here is a VBScript that reads/converts to plain text and outputs the value.

它存储在名为 TranscodedImageCache (REG_BINARY) 的值中。这是一个读取/转换为纯文本并输出值的 VBScript。

How to Determine the Current Wallpaper File Name and Path in Windows 8 - The Winhelponline Blog

如何确定 Windows 8 中的当前壁纸文件名和路径 - Winhelponline 博客