在VB.NET中获取当前用户的壁纸

时间:2011-01-31 19:38:34

标签: vb.net

我正在用VB.NET编写一个程序,需要获取当前用户壁纸的路径。有人知道会这样做的方法吗?

3 个答案:

答案 0 :(得分:3)

您可以从注册表中读取当前壁纸。无需任何API调用。 这是执行该操作的代码

Private Function GetCurrentWallpaper() As String
    ' The current wallpaper path is stored in the registry at HKCU\Control Panel\Desktop\WallPaper
    Dim rkWallPaper As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", False)
    Dim WallpaperPath As String = rkWallPaper.GetValue("WallPaper").ToString()
    rkWallPaper.Close()
    ' Return the current wallpaper path
    Return WallpaperPath
End Function

答案 1 :(得分:3)

我知道现在已经很晚了,但对于其他任何人......如果桌面背景(壁纸)是图片(不是纯色),您可以在目录中找到当前图片:

“C:\ Users \ {username} \ AppData \ Roaming \ Microsoft \ Windows \ Themes \”

答案 2 :(得分:2)

您必须使用SPI_GETDESKWALLPAPER对SystemParametersInfo()进行pinvoke。这将返回壁纸位图文件的路径。访问pinvoke.net获取所需的声明。