I have a batch script that lets users change their background from black to white or vice versa. The problem I'm having is that the script only makes immediate change sometimes, and other times the user has to log off and log back on for the background to change. Here is what I have so far:
#echo off
call :quiet
exit /b
:quiet
:: For comparison, using the black wallpaper registry value
set "black=C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\MDCBackground_black.bmp"
:: Set reg query result to current
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKCU\Control Panel\Desktop" /v Wallpaper') DO SET current=%%B
:: For debugging purpose.
ECHO current=%current%
pause
if "%current%"=="%black%" (
call :MakeDayWallpaper>nul 2>&1
:: Make changes without requiring logoff
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
) else (
call :MakeNightWallpaper>nul 2>&1
:: Make changes without requiring logoff
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
)
EXIT /b
:MakeDayWallpaper
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\MDCBackground_white.bmp" /f
REG DELETE "hkcu\Software\Microsoft\Internet Explorer\Desktop\General" /v Wallpaper /f
REG ADD "hkcu\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
EXIT /b
:MakeNightWallpaper
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\MDCBackground_black.bmp" /f
REG DELETE "hkcu\Software\Microsoft\Internet Explorer\Desktop\General" /v Wallpaper /f
REG ADD "hkcu\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
EXIT /b
The line RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters is the command that allows the immediate change. When I look at shell I can see that the registry value is changing every time the script is executed, but despite this fact, sometimes the background does not change until the user logs off and logs on.
It might be that the registry changes aren't taking effect until the log off/log on is done (I'm not sure why it would sometimes work immediately though). Try restarting explorer afterwards and see if that helps.
taskkill /im explorer.exe /f
explorer.exe
Related
I need to open it on startup to change the wallpaper at day n night
Dim objShell
str1 = "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day.bat"
str2 = "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Night.bat"
Set objShell = Wscript.CreateObject("WScript.Shell")
if hour(time) < 17 then
objShell.Run str1
if hour(time) > 16 then
objShell.Run str2
end if
end if
This is the vbs that will open batch files that will change the Reg
Batch file for day
#echo off
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Day.png" /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
Batch file for night
#echo off
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Night.png" /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
but when i use the vbs it did not change the registry
Please Help
Thanks
I would do it like this, (especially because the output of %TIME% is machine dependent):
#Echo Off
Set "locn=%UserProfile%\Desktop\Texts\Projects\Project WallTime"
Set "rstr=Reg Add "HKCU\Control Panel\Desktop" /V Wallpaper /D "
Set "str1=%locn%\Day.bat"
Set "str2=%locn%\Night.bat"
Set /A "now=10%TIME:~,2%" 2>Nul
If %now:~-2% Lss 17 (%rstr% "%str1%" /F >Nul
) Else %rstr% "%str2%" /F >Nul
RunDll32 User32.dll,UpdatePerUserSystemParameters >Nul
Just create a single batch file, without the VBS and run it.
Note!! there are delays caused with rundll32.exe if being run after another, so if this runs continually to test, it will not update each time.
#echo off
setlocal enabledelayedexpansion
set "Wtime=!time:~0,2!"
if "!Wtime!" leq "17" reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Day.png" /f & goto done
if "!Wtime!" geq "17" reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "D:\C:\Users\AnB\Desktop\Texts\Projects\Project WallTime\Day and Night\Night.png" /f & goto done
:done
timeout /t 5 >nul
start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
endlocal
keep in mind, enabledelayedexpansion is not really needed here.
I added an item to startup using the command
REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
And after I tryed to delete it with the command :
REG DELETE "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OMG" /f
But with no succes. I searched for this type of question but with no result. I will realy apreciate any help!
rem ↓↓ missing " double quote
REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
rem ↑↑ missing " double quote
Missing " double quote causes misinterpreting keys as follows:
==> REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
The operation completed successfully.
==> reg query "HKCU\Software\Microsoft\Windows\CurrentVersion" /S | findstr /C:"CurrentVersion\Run " 2>NUL
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:\WGET
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:\WGET\wget.exe
==>
Add missing " double quote as follows:
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
Yup, You missed the 'Double Quotes' After REG ADD. But, in this method you are choosing, You need to run the script as an 'Admin'. While, Giving a Batch file Admin Access Can never be a good idea.
So, You can try the alternative of, Copying the Shortcut (the file to Execute at startup) to the path -> "%Userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" - No Admin Needed. :)
Im sure as hell not in any way an experienced coder, so bear with me with these questions.
Im trying to change a LoadBehavior REG_DWORD 0x00000002(2) to a value 0x00000003(3) in several folders incl their subfolders. I want the script to run through each of the folders and subfolders and change the value to 3 if they find the REG_DWORD type.
I dont want it to add a REG_DWORD if there isnt any.
Edit:
After help from JosefZ I have edited my code below:
Its probably an easy fix for you fellow coders :) Looking forward to hearing from you
My whole code listed below:
#echo off
echo Start af Registry p† remote pc
set /p input="Maskinens wrk-nummer:"
sc \\%input% config remoteregistry start= auto
sc \\%input% start remoteregistry
reg query \\%input%\hku /v LoadBehavior /s | find /I "HKEY_USERS\"
for /F "tokens=*" %%G in ('
reg query \\%input%\hku /v LoadBehavior /s 2^>NUL ^| find /I "HKEY_USERS\"
') do (
rem next command is merely displayed for debugging purposes
echo REG ADD \\%input%\%%G /v LoadBehavior /d "3" /t REG_DWORD /f
rem remove `ECHO` from above command no sooner than debugged
)
Choice /M "Vil du gerne ogs† †bne Registry?"
If Errorlevel 2 Goto No
If Errorlevel 1 Goto Yes
Goto End
:No
Echo Programmet lukker
Goto End
:Yes
Echo Registry †bner
start regedit.exe
:End
timeout 2
Results running the code above:
Start af Registry på remote pc
Maskinens wrk-nummer:wrk0022423
[SC] ChangeServiceConfig SUCCESS
[SC] StartService FAILED 1056:
Der kører allerede en udgave af tjenesten.
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Excel\Addins\AdHocReportingExcelClientLib.AdHocReportingExcelClientAddIn.1
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Excel\Addins\DYMO.LabelWriterAddIn
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Excel\Addins\PowerPivotExcelClientAddIn.NativeEntry.1
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\AccessAddin.DC
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\Add-On-Products.ResourceFinder
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\ColleagueImport.ColleagueImportAddin
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\DYMO.LabelWriterAddIn
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\TelemetryAddin.Connect
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\PowerPoint\Addins\OneNote.PowerPointAddinTakeNotesService
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Word\Addins\DYMO.LabelWriterAddIn
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Word\Addins\OneNote.WordAddinTakeNotesService
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Excel\Addins\AdHocReportingExcelClientLib.AdHocReportingExcelClientAddIn.1 /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Excel\Addins\DYMO.LabelWriterAddIn /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Excel\Addins\PowerPivotExcelClientAddIn.NativeEntry.1 /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\AccessAddin.DC /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\Add-On-Products.ResourceFinder /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\ColleagueImport.ColleagueImportAddin /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\DYMO.LabelWriterAddIn /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Outlook\Addins\TelemetryAddin.Connect /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\PowerPoint\Addins\OneNote.PowerPointAddinTakeNotesService /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Word\Addins\DYMO.LabelWriterAddIn /v LoadBehavior /d "3" /t REG_DWORD /f
REG ADD \\wrk0022423\HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\SOFTWARE\Microsoft\Office\Word\Addins\OneNote.WordAddinTakeNotesService /v LoadBehavior /d "3" /t REG_DWORD /f
Vil du gerne også åbne Registry? [Y,N]?
To show all subkeys where a value occurs (used temp value name instead of LoadBehavior merely for demostration):
==> reg query \\%input%\hku /v temp /s | find /I "HKEY_USERS\"
HKEY_USERS\.DEFAULT\Environment
HKEY_USERS\S-1-5-21-3900305277-3673560937-2769375459-163256\Environment
HKEY_USERS\S-1-5-18\Environment
Use next for /F loop instead of reg add … in your code:
for /F "tokens=*" %%G in ('
reg query \\%input%\hku /v LoadBehavior /s 2^>NUL ^| find /I "HKEY_USERS\"
') do (
rem next command is merely displayed for debugging purposes
echo REG ADD \\%input%\%%G /v LoadBehavior /d "3" /t REG_DWORD /f
rem remove `ECHO` from above command no sooner than debugged
)
Did anybody know how to modify the character size in cmd. I already searched on internet but all what I found was the method from Proprieties. I need something like mode x,y but for characters.
You can not change (or at least i don't know how to do it) the properties of the current console from command line without some third party tool.
BUT, you can customize the creation of a new console
#echo off
setlocal enableextensions disabledelayedexpansion
set "consoleName=testing"
:: http://technet.microsoft.com/en-us/library/cc978570.aspx
( reg add "HKCU\Console\%consoleName%" /f
reg add "HKCU\Console\%consoleName%" /f /v "FaceName" /t "REG_SZ" /d "Consolas"
reg add "HKCU\Console\%consoleName%" /f /v "FontFamily" /t "REG_DWORD" /d 0x00000036
reg add "HKCU\Console\%consoleName%" /f /v "FontSize" /t "REG_DWORD" /d 0x00080004
reg add "HKCU\Console\%consoleName%" /f /v "FontWeight" /t "REG_DWORD" /d 0x00000000
reg add "HKCU\Console\%consoleName%" /f /v "QuickEdit" /t "REG_DWORD" /d 0x00000000
reg add "HKCU\Console\%consoleName%" /f /v "ScreenBufferSize" /t "REG_DWORD" /d 0x00200040
reg add "HKCU\Console\%consoleName%" /f /v "WindowSize" /t "REG_DWORD" /d 0x00200040
) > nul
start "%consoleName%" cmd.exe
The registry stores the configuration for multiple customizations of the console. This code just creates a basic customization associated to a window title and starts a new console with this title to use the indicated parameters.
For more information, the documentation includes a complete reference of the values.
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 "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'. Scheduler will run them every day at needed time