Windows Cmd Delete Item from HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run - windows

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. :)

Related

Batch, adding quotes to argument stops reg from working

So i tried to make a batch file that runs when a txt file is opened.
reg add HKCR\txtfile\shell\open\command /ve /t REG_EXPAND_SZ /d %0 /f
So far so good. But when i open the text document theres an error due to spaces in %0.
reg add HKCR\txtfile\shell\open\command /ve /t REG_EXPAND_SZ /d "%0" /f
This doesnt give me an error, but the registry value doesnt change.
reg add HKCR\txtfile\shell\open\command /ve /t REG_EXPAND_SZ /d ^"%0^" /f
Same thing.
So whats my problem here?
The escape character in this case, (complete lack of consistency, I know), is the back slash:
Reg Add "HKCR\txtfile\shell\open\command" /VE /D \"%~0\" /F >Nul

Making a script to change regedit values in all folders and subfolders

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
)

(Windows 8.1) Get path of selected folder from custom context menu option

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

Cmd character font size

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.

Windows batch command to make changes effective immediately

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

Resources