Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Скриптовые языки администрирования Windows (http://forum.oszone.net/forumdisplay.php?f=102)
-   -   [решено] Смена обоев рабочего стола (http://forum.oszone.net/showthread.php?t=299767)

Bio_Hazard 14-05-2015 13:15 2507234

Смена обоев рабочего стола
 
Здравствуйте. Хочу сделать, что бы при запуске скрипта на рабочем столе случайным образом менялись обои из папки (например e:\Изображения\Обои для рабочего стола\). Стоит Windows 7 Ultimate. Стандартными средствами реализовано похожее, но там через время, что меня не совсем устраивает. Создавал похожую тему http://forum.oszone.net/showthread.php?p=2507233, но там не ответили. Реально ли это сделать?

Kazun 14-05-2015 14:05 2507250

http://poshcode.org/491 - Set-Wallpaper

Код:

add-type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
  public enum Style : int
  {
      Tile, Center, Stretch, NoChange
  }


  public class Setter {
      public const int SetDesktopWallpaper = 20;
      public const int UpdateIniFile = 0x01;
      public const int SendWinIniChange = 0x02;

      [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
      private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
     
      public static void SetWallpaper ( string path, Wallpaper.Style style ) {
        SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
       
        RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
        switch( style )
        {
            case Style.Stretch :
              key.SetValue(@"WallpaperStyle", "2") ;
              key.SetValue(@"TileWallpaper", "0") ;
              break;
            case Style.Center :
              key.SetValue(@"WallpaperStyle", "1") ;
              key.SetValue(@"TileWallpaper", "0") ;
              break;
            case Style.Tile :
              key.SetValue(@"WallpaperStyle", "1") ;
              key.SetValue(@"TileWallpaper", "1") ;
              break;
            case Style.NoChange :
              break;
        }
        key.Close();
      }
  }
}
"@

Get-ChildItem "e:\Изображения\Обои для рабочего стола\*.jpg" -Recurse  | Get-Random -Count 1  | Foreach {[Wallpaper.Setter]::SetWallpaper( $_.FullName, "NoChange" )}


Set Random Wallpaper on your Desktop using Powershell - https://gallery.technet.microsoft.co...Using-e79e4235

Bio_Hazard 14-05-2015 16:35 2507288

Kazun, спасибо! Первый скрипт работает отлично!!!
Есть 2 вопроса:
1) можно ли его подредактировать, что бы он открывал еще *.jpeg *.png *.gif
2) Картинки нужно подкорректировать по размерах или они сами масштабируются?

Kazun 14-05-2015 16:46 2507294

1. Get-ChildItem -Path "e:\Изображения\Обои для рабочего стола\*" -Include *.jpeg,*.png,*.gif -Recurse

2. Вместо NoChange, доступно еще 3:Stretch(Растянуть),Center(По центру),Tile(Замостить)

https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

Код:

[Control Panel\Desktop]
Wallpaper=%WinDir%\web\wallpaper\Windows\img0.jpg
; The path to the wallpaper picture can point to a
; .bmp, .gif, .jpg, .png, or .tif file.

TileWallpaper=0
; 0: The wallpaper picture should not be tiled
; 1: The wallpaper picture should be tiled

WallpaperStyle=2
; 0:  The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1
; 2:  The image is stretched to fill the screen
; 6:  The image is resized to fit the screen while maintaining the aspect
      ratio. (Windows 7 and later)
; 10: The image is resized and cropped to fill the screen while maintaining
      the aspect ratio. (Windows 7 and later)

Посмотреть, как выглядят различные параметры - http://newdelhipowershellusergroup.b...positions.html

Bio_Hazard 14-05-2015 20:01 2507362

Kazun, Спасибо! Решено.

Iska 15-05-2015 09:19 2507590

Цитата:

Цитата Bio_Hazard
2) Картинки нужно подкорректировать по размерах или они сами масштабируются? »

При желании можно и масштабировать, и обрезать, и растягивать и много чего ещё. Это касаемо манипуляций над самими изображениями, помимо настроек, указанных коллегой Kazun.


Время: 14:45.

Время: 14:45.
© OSzone.net 2001-