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.
Related
I'm trying to change some registry entries through a batch file.
All seems to work properly except these two:
reg add "HKEY_CURRENT_USER\Control Panel\International" /t REG_SZ /v sCountry /d "België" /f
reg add "HKEY_CURRENT_USER\Control Panel\International" /t REG_SZ /v sCurrency /d "€" /f
These give me some odd values instead of the ones I want entered I get the values in the image provided here:
Image
Any hints as to why/how to fix it?
Here's a quick example based upon my comment, (using codepage 1252):
#Echo Off
SetLocal EnableExtensions
Set "RegKey=HKCU\Control Panel\International"
Rem This line will undefine any variable with a name beginning _cp
For /F Delims^= %%G In ('Set _cp 2^>NUL')Do Set "%%G="
Rem This line will save your current codepage to the variable %_cp%
For /F Tokens^=* %%G In ('"%__AppDir__%chcp.com"')Do For %%H In (%%G)Do Set "_cp=%%~nH"
Rem This line will change the codepage to 1252 if it is not already 1252
If Not %_cp% Equ 1252 (Set "_cpc=TRUE"
"%__AppDir__%chcp.com" 1252 >NUL)
"%__AppDir__%reg.exe" Add "%RegKey%" /V "sCountry" /D "België" /F >NUL
"%__AppDir__%reg.exe" Add "%RegKey%" /V "sCurrency" /D "€" /F >NUL
Rem This line will change the codepage back if it was not already 1252
If Defined _cpc "%__AppDir__%chcp.com" %_cp% >NUL
First of all, I have almost no idea about batch language. I'm working on a batch file that writes to the registry in order to add a context menu option that removes "desktop.ini" from the folder from where the context menu option is called. So far, what I got is:
#echo off
#reg add "HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings" /t REG_SZ /v "" /d "Reset folder settings" /f
rem #reg add "HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings\command" /t REG_SZ /v "" /d "del /A s h \"%cd%\desktop.ini\" && pause" /f
#reg add "HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings\command" /t REG_SZ /v "" /d "cmd.exe /c echo \"%~dp0\desktop.ini\" && pause" /f
pause
Which doesn't work because what gets written into the registry is the static folder path from where the installation .bat is called. I'm having quite some trouble finding a solution to this problem so I finally decided I had no choice but to ask for help here.
Use %V to denote the folder from where the context menu option is called.
Hence, the parameters you should use in
reg add "HKCR\Folder\shell\resetFolderSettings\command" ...
could be from a batch script (see that %V should be escaped as %%V):
... /t REG_SZ /v "" /d "%comspec% /c echo \"%%V\desktop.ini\"&&pause" /F
or directly from cmd window - % sign is not escaped here:
... /t REG_SZ /v "" /d "%comspec% /c echo \"%V\desktop.ini\"&&pause" /F
Edit. To make %comspec% expandable as well (and with operational del /A command instead of echo):
... /t REG_EXPAND_SZ /ve /d ^%comspec^%" /c del /A \"%V\desktop.ini\"&pause" /F
used directly from cmd window. See escaped % as ^% (however only those out of double-quoted part of command line) above.
Use another escaping scheme from a batch-script: escape all % as %% how seen in both %%comspec%% and %%V as follows:
... /t REG_EXPAND_SZ /ve /d "%%comspec%% /c del /A \"%%V\desktop.ini\"&pause" /F
Result:
==> reg query "HKCR\Folder\shell\resetFolderSettings\command" /ve
HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings\command
(Default) REG_EXPAND_SZ %comspec% /c del /A "%V\desktop.ini"&pause
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.
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
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