简体   繁体   English

Windows 批处理脚本切换桌面背景

[英]Windows batch script to switch desktop background

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.我对 Windows 批处理脚本有点不熟悉,我正在寻求一些关于如何完成上述任务的提示和建议。 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 "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "%SystemRoot%\energybliss.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 2


:: Configure the screen saver.
:: REG ADD "HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\scrnsave.scr"
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1


:: Set the time out to 900 seconds (15 minutes).
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaveTimeOut /T REG_SZ /F /D 900


:: Set the On resume, password protect box 
:: REG ADD "HKCU\Control Panel\Desktop" /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 "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispScrSavPage /T REG_DWORD /F /D 1
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispBackgroundPage /T REG_DWORD /F /D 1
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispAppearancePage /T REG_DWORD /F /D 1

:: Make the changes effective immediately
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

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 "HKCU\Control Panel\Desktop" /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'.您可以制作 2 个名为“makeday.bat”和“makenight.bat”的文件。 Scheduler will run them every day at needed time调度程序将在每天需要的时间运行它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM