Ejemplo n.º 1
0
        /// <summary>
        ///   Gets the wallpaper arrangement.
        /// </summary>
        /// <remarks>
        ///   This method returns <c>null</c> if the registry value is invalid or cannot be found.
        /// </remarks>
        /// <returns>
        ///   A <see cref="Nullable{WallpaperArrangement}" />? object representing the current
        ///   wallpaper arrangement. <c>null</c> if the registry value is invalid or cannot be found.
        /// </returns>
        /// <inheritdoc cref="GetWallpaperPath" />
        public static WallpaperArrangement?GetWallpaperArrangement()
        {
            using (RegistryKey desktopRegKey =
                       Registry.CurrentUser.OpenSubKey(Desktop.ControlPanelDesktopRegistryKey, false)
                   ) {
                String wallpaperStyle = Desktop.GetRegString(desktopRegKey, Desktop.WallpaperStyleRegistryValue);
                String wallpaperTile  = Desktop.GetRegString(desktopRegKey, Desktop.WallpaperTileRegistryValue);

                if (
                    (wallpaperStyle == null) || (wallpaperTile == null) ||
                    (wallpaperStyle.Length != 1) || (wallpaperTile.Length != 1))
                {
                    return(null);
                }

                if (wallpaperTile[0] == '1')
                {
                    return(WallpaperArrangement.Tile);
                }

                if (wallpaperStyle[0] == '1')
                {
                    return(WallpaperArrangement.Center);
                }

                if (wallpaperStyle[0] == '2')
                {
                    return(WallpaperArrangement.Stretch);
                }

                return(null);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///   Gets the path of the active wallpaper.
 /// </summary>
 /// <remarks>
 ///   The path returned may also be empty or invalid.
 ///   <c>null</c> will be returned if the key or value doesn't exist or isn't of type String.
 /// </remarks>
 /// <returns>
 ///   A <see cref="String" /> representing the active wallpaper path.
 ///   <c>null</c> if the key or value doesn't exist or isn't of type string.
 /// </returns>
 /// <exception cref="SecurityException">
 ///   Missing framework access rights to read the registry key or its value.
 ///   Or missing windows access rights to read the registry key.
 /// </exception>
 /// <exception cref="UnauthorizedAccessException">
 ///   Missing Windows access rights to read the registry value.
 /// </exception>
 /// <permission cref="RegistryPermission">
 ///   for reading the registry key and value. Associated enumerations:
 ///   <see cref="RegistryPermissionAccess.Read">RegistryPermissionAccess.Read</see>.
 /// </permission>
 /// <permission cref="SecurityPermission">
 ///   for the ability to access the specified registry key, if it is a remote key.
 ///   Associated enumeration:
 ///   <see cref="SecurityPermissionFlag.UnmanagedCode">SecurityPermissionFlag.UnmanagedCode</see>.
 /// </permission>
 public static String GetWallpaperPath()
 {
     using (RegistryKey desktopRegKey =
                Registry.CurrentUser.OpenSubKey(Desktop.ControlPanelDesktopRegistryKey, false)
            ) {
         return(Desktop.GetRegString(desktopRegKey, Desktop.WallpaperPathRegistryValue));
     }
 }