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
)
Related
I'm trying to create a simple batch file that uses the reg query command to check for the existence of a value in a registry key, specifically
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings ProxyEnable key.
If I run this command:
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /f 0x1 /d
It returns the following:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
ProxyEnable REG_DWORD 0x0
It's as if it's not accepting my /f search field, as I would expect the command as entered to return no results since my value for that key is 0x0.
I've tried using quotes around the "0x1", and other combinations, but wondering if I'm doing something wrong.
Thanks in advance!
As you only appear to be wanting to know if enabling proxy is toggled on, you can use this instead:
#Echo Off
Set "RR=HKCU"
Set "RK=Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set "RV=ProxyEnable"
For /F "Skip=1 Tokens=2*" %%A In ('Reg Query "%RR%\%RK%" /V "%RV%" 2^>Nul'
) Do If %%~B Gtr 0 Echo(%%B
Pause
If you wanted to for instance to toggle it on if it is off then change it to something like this:
#Echo Off
Set "RR=HKCU"
Set "RK=Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set "RV=ProxyEnable"
For /F "Skip=1 Tokens=2*" %%A In ('Reg Query "%RR%\%RK%" /V "%RV%" 2^>Nul'
) Do If %%~B Equ 0 Reg Add "%RR%\%RK%" /V "%RV%" /T REG_DWORD /D 0x1 /F>Nul
Although technically you could just run this to do that:
#Echo Off
Set "RR=HKCU"
Set "RK=Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set "RV=ProxyEnable"
Reg Add "%RR%\%RK%" /V "%RV%" /T REG_DWORD /D 0x1 /F>Nul
Edit
To check it first using the method suggested by Squashman and improved by zett42, because the following EnableHttp1_1 REG_DWORD 0x0 would have been sent to Find:
#Echo Off
Set "RR=HKCU"
Set "RK=Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set "RV=ProxyEnable"
Reg Query "%RR%\%RK%" /F 1 /E /T REG_DWORD|Find /I "%RV%">Nul 2>&1||(
Reg Add "%RR%\%RK%" /V "%RV%" /T REG_DWORD /D 0x1 /F>Nul)
Reg query is for read registry data not for set or change the registry data
to change the Registry data replace query with Add
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /d 0x1 /f
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. :)
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