Как изменить обои через bat

Бывают моменты, когда нам надо сменить изображение рабочего стола, но по каким-то неизвестным причинам это сделать не получается. Кроме того, любители программирования могут также задаться таким вопросом можно ли сменить картинку рабочего стола с помощью программы? Ответ можно. И…

April 4 2011, 13:53

Category:

  • IT
  • Cancel

Программный способ смены фона рабочего стола

Бывают моменты, когда нам надо сменить изображение рабочего стола, но по каким-то неизвестным причинам это сделать не получается. Кроме того, любители программирования могут также задаться таким вопросом — можно ли сменить картинку рабочего стола с помощью программы? Ответ — можно. И сейчас мы это сделаем собственными силами, не прибегая к поиску программы в интернете и к ее скачиванию.

На самом деле всё просто до невозможности. Вся проблема заключается в том, что для сохранения рисунка в качестве фона рабочего стола необходимо прописать адрес рисунка в системном реестре, а потом сделать обновление реестра. Адрес изображения прописать можно и вручную, но вот обновление реестра не происходит, чтобы мы сразу могли любоваться нужным фоном.

Создаваемый нами скрипт на языке Visual Basic добавит информацию об адресе файла в реестр и обновит изменения в системе. Но для того, чтобы всё работало, нам нужно, чтобы изображение было только в формате bmp. Все необходимые файлы лучше разместить в одной папке. Начнем.

Создаем в выбранной нами папке текстовый файл. Затем добавляем в него следующий скрипт:

Set objWshShell = WScript.CreateObject(«Wscript.Shell»)
strPath2DestWallpaper = «*.bmp»
objWshShell.RegWrite «HKEY_CURRENT_USERControl PanelDesktopWallpaper», strPath2DestWallpaper, «REG_SZ»
objWshShell.Run «»»%SystemRoot%System32RUNDLL32.EXE»» user32.dll,UpdatePerUserSystemParameters», 0, True

В строке strPath2DestWallpaper = «*.bmp« вместо звёздочки вставляем путь к вашему изображению. Сохраняем наш текстовый документ в формате vbs. Например, wall.vbs

Открыть

Скрипт готов. Теперь можно его запустить. Однако, изменения рабочего стола будут до завершения сеанса пользователя. При последующей загрузке Windows вместо картинки на рабочем столе будет просто фоновый цвет. Чтобы это исправить, необходимо создать исполняемый файл, который и будет запускать наш скрипт.

Создаем в нашей папке текстовый документ и пишем в нем следующее:

wscript.exe //NOLOGO wall.vbs

 

Сохраняем документ с расширением .bat, например wall.bat. Далее создаем для него ярлык и кидаем этот ярлык в папку Автозагрузка. Вот и всё! Теперь при каждой загрузке Windows будет автоматически запускаться наш исполняемый файл. Не забудьте только, чтобы все три файла находились в одной папке.

Is there a way to check what a user currently has as their background and then changing it depending on what it is? For example: I want a white background during day time and a black background for night time. Running the script would check the current background, if it is white it will switch to the black background, and if it is black it will switch to the white.

I’m a little unfamiliar with Windows batch script and I’m seeking some tips and advice on how I can accomplish the task above. Here is what I’ve been able to find so far:

@echo off
call :quiet>nul 2>&1
goto :EOF

:quiet


:: Configure Wallpaper 
REG ADD "HKCUControl PanelDesktop" /V Wallpaper /T REG_SZ /F /D "%SystemRoot%energybliss.bmp"
REG ADD "HKCUControl PanelDesktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCUControl PanelDesktop" /V TileWallpaper /T REG_SZ /F /D 2


:: Configure the screen saver.
:: REG ADD "HKCUControl PanelDesktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%System32scrnsave.scr"
:: REG ADD "HKCUControl PanelDesktop" /V ScreenSaveActive /T REG_SZ /F /D 1


:: Set the time out to 900 seconds (15 minutes).
:: REG ADD "HKCUControl PanelDesktop" /V ScreenSaveTimeOut /T REG_SZ /F /D 900


:: Set the On resume, password protect box 
:: REG ADD "HKCUControl PanelDesktop" /V ScreenSaverIsSecure /T REG_SZ /F /D 1


:: Remove the user's ability to see the Screen Saver, background, and appearance tabs of Display Properties. 
::REG ADD "HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem" /V NoDispScrSavPage /T REG_DWORD /F /D 1
::REG ADD "HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem" /V NoDispBackgroundPage /T REG_DWORD /F /D 1
::REG ADD "HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem" /V NoDispAppearancePage /T REG_DWORD /F /D 1

:: Make the changes effective immediately
%SystemRoot%System32RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

Mrchief's user avatar

Mrchief

74.6k19 gold badges141 silver badges188 bronze badges

asked Aug 12, 2011 at 14:38

icanc's user avatar

You can use code like that:

@echo off

:: '>nul 2>&1' was moved to other place
call :quiet
exit /b

:quiet
    :: Put there wallpaper name (with extension, bigger that 8 symbols)
    set "Wallpaper.Night.BadWrited=Wallpaper1.bmp"

    :: It is a dirty hack and example of bad code
    for /F "tokens=*" %%a in ('reg query "HKCUControl PanelDesktop" /v Wallpaper') do     set "Wallpaper.Current.BadWrited=%%a"

    :: Take last 8 symbols of wallpaper name. Change number of symbols to your own  minimal
    set "Wallpaper.Current.BadWrited=%Wallpaper.Current.BadWrited:~-8%"
    set "Wallpaper.Night.BadWrited=%Wallpaper.Night.BadWrited:~-8%"

    if "%Wallpaper.Current.BadWrited%"=="%Wallpaper.Night.BadWrited%" (
        call :MakeDayWallpaper>nul 2>&1
    ) else (
        call :MakeNightWallpaper>nul 2>&1
    )
exit /b

:MakeDayWallpaper
    echo Day wallpaper setted
    :: Put your code here
exit /b

:MakeNightWallpaper
    echo Night wallpaper setted 
    :: Put your code here
exit /b

But i recommend to use the system scheduler. You can acces it from control panel, ‘Scheduled Tasks’ or something. You can make 2 files named ‘makeday.bat’ and ‘makenight.bat’. Scheduler will run them every day at needed time

answered Aug 12, 2011 at 21:25

Viktor Lova's user avatar

Viktor LovaViktor Lova

4,6962 gold badges18 silver badges25 bronze badges

2

Is there a way to check what a user currently has as their background and then changing it depending on what it is? For example: I want a white background during day time and a black background for night time. Running the script would check the current background, if it is white it will switch to the black background, and if it is black it will switch to the white.

I’m a little unfamiliar with Windows batch script and I’m seeking some tips and advice on how I can accomplish the task above. Here is what I’ve been able to find so far:

@echo off
call :quiet>nul 2>&1
goto :EOF

:quiet


:: Configure Wallpaper 
REG ADD "HKCUControl PanelDesktop" /V Wallpaper /T REG_SZ /F /D "%SystemRoot%energybliss.bmp"
REG ADD "HKCUControl PanelDesktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCUControl PanelDesktop" /V TileWallpaper /T REG_SZ /F /D 2


:: Configure the screen saver.
:: REG ADD "HKCUControl PanelDesktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%System32scrnsave.scr"
:: REG ADD "HKCUControl PanelDesktop" /V ScreenSaveActive /T REG_SZ /F /D 1


:: Set the time out to 900 seconds (15 minutes).
:: REG ADD "HKCUControl PanelDesktop" /V ScreenSaveTimeOut /T REG_SZ /F /D 900


:: Set the On resume, password protect box 
:: REG ADD "HKCUControl PanelDesktop" /V ScreenSaverIsSecure /T REG_SZ /F /D 1


:: Remove the user's ability to see the Screen Saver, background, and appearance tabs of Display Properties. 
::REG ADD "HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem" /V NoDispScrSavPage /T REG_DWORD /F /D 1
::REG ADD "HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem" /V NoDispBackgroundPage /T REG_DWORD /F /D 1
::REG ADD "HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem" /V NoDispAppearancePage /T REG_DWORD /F /D 1

:: Make the changes effective immediately
%SystemRoot%System32RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

Mrchief's user avatar

Mrchief

74.6k19 gold badges141 silver badges188 bronze badges

asked Aug 12, 2011 at 14:38

icanc's user avatar

You can use code like that:

@echo off

:: '>nul 2>&1' was moved to other place
call :quiet
exit /b

:quiet
    :: Put there wallpaper name (with extension, bigger that 8 symbols)
    set "Wallpaper.Night.BadWrited=Wallpaper1.bmp"

    :: It is a dirty hack and example of bad code
    for /F "tokens=*" %%a in ('reg query "HKCUControl PanelDesktop" /v Wallpaper') do     set "Wallpaper.Current.BadWrited=%%a"

    :: Take last 8 symbols of wallpaper name. Change number of symbols to your own  minimal
    set "Wallpaper.Current.BadWrited=%Wallpaper.Current.BadWrited:~-8%"
    set "Wallpaper.Night.BadWrited=%Wallpaper.Night.BadWrited:~-8%"

    if "%Wallpaper.Current.BadWrited%"=="%Wallpaper.Night.BadWrited%" (
        call :MakeDayWallpaper>nul 2>&1
    ) else (
        call :MakeNightWallpaper>nul 2>&1
    )
exit /b

:MakeDayWallpaper
    echo Day wallpaper setted
    :: Put your code here
exit /b

:MakeNightWallpaper
    echo Night wallpaper setted 
    :: Put your code here
exit /b

But i recommend to use the system scheduler. You can acces it from control panel, ‘Scheduled Tasks’ or something. You can make 2 files named ‘makeday.bat’ and ‘makenight.bat’. Scheduler will run them every day at needed time

answered Aug 12, 2011 at 21:25

Viktor Lova's user avatar

Viktor LovaViktor Lova

4,6962 gold badges18 silver badges25 bronze badges

2

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Как изменить обои на экране блокировки айфон
  • Как изменить обои рабочего стола через командную строку
  • Как изменить обои на экране блокировки xiaomi
  • Как изменить обои приложений на айфоне
  • Как изменить обои на часах хуавей

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии