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
Related
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. :)
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
I'm trying to edit the Registry value using a batch file, this is what I currently have:
#echo off
reg add "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Explorer" /v "1" /t REG_SZ /d "DisableThumbsDBOnNetworkFolders" /f
pause
This is what I'm trying to edit:
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\ Explorer]
DisableThumbsDBOnNetworkFolders REG_DWORD 0x00000001
I want to set the value to 1 (0x00000001) (By default it's 0x00000000)
But my cmd file creates another value named DisableThumbsDBOnNetworkFolders .
What did I do wrong?
You have a couple problems.
The /v parameter is the value name, in your case DisableThumbsDBOnNetworkFolders, and the /d parameter should be the actual value.
It looks like DisableThumbsDBOnNetworkFolders is a REG_DWORD, but you are specifying it as REG_SZ with the /t parameter.
Try this command:
REG ADD "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Explorer" /v "DisableThumbsDBOnNetworkFolders" /t REG_DWORD /d 1 /f
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've resolved the question I had about inserting %DATE% into a REG_SZ registry value (see link), but now I'm running into a slightly different problem trying to insert %~DP0 (long source path) into a registry value using REG ADD within a .BAT script. It won't do it, and I'm sure it's because I'm doing something wrong.
reg add "hklm\software\acme" /v "TestValue" /d "%~dp0" /t REG_SZ /f
I've also tried setting the value to a variable first, but that doesn't work either. What happens is that it inserts the expanded path without the preceeding double-quote, but with a trailing double-quote, and then bombs with an error about REG /? syntax, etc.
SET VX=%~DP0
reg add "hklm\software\acme" /v "TestValue" /d "%VX%" /t REG_SZ /f
Anyone see what I'm doing wrong?
The path %~dp0 ends in the directory separator character '\' (e.g. 'c:\temp\') which is being interpreted as an escape for the following double-quote character and so the parser is not seeing the closing double-quote. What you need to do is escape the trailing \ character with another one:
reg add "hklm\software\acme" /v "TestValue" /d "%~dp0\" /t REG_SZ /f