Batch file to edit Registry value? - windows

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

Related

edit regedit value using bat file

I am trying to change the value of a reg_dword entry: start in location: Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv
to value 2.
I tried already exacting code from several sites, nothing works and I am launching it as admin:
REG.exe ADD "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /t REG_DWORD /v Start /d 2 /f
REG ADD "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /t REG_DWORD /v Start /d 2 /f
REG.exe ADD "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /v "Start" /t REG_DWORD /d 2 /f
On every site there was information with slight difference, but i don't think order matter, maybe "".
What is the correct syntax for adding a registry value as described above?
Your problem is the Computer.
Indeed, the order of the options does not matter. Also it doesn't matter if you call REG or REG.exe.
Usually, the inbuilt help is also your friend:
reg add /?
Which tells you that Computer is the (network) name of the remote computer and can be omitted to use the current (local) computer as default.
This line works fine (as any other of yours without the Computer\:
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hidserv" /t REG_DWORD /v Start /d 3 /f
Offtopic: Check out the other networks of stackexchange. I'd think this question would be more suitable for https://superuser.com/.

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

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

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

Change a Registry Value, then Run an Application, by Using a Batch File

I want to change a registry value (a REG_DWORD), then run an application, by using a batch file, that is located in the same folder as the application.
I tried the lines below, but that does not work:
reg add "HKEY_CURRENT_USER\A User Name\An Application Name" /v A value name_h3981298716 /d "99" /t REG_DWORD /f
START %~dp0AnApplicationName.exe
The "START ..." will work without the "reg add ..." code. The batch file can run an application, but it cannot change a registry value of REG_DWORD type.
How to do the sequence below correctly with a batch file?
First, change a registry value of REG_DWORD type.
Then run an application.
reg add "HKCU\A User Name\An Application Name" /v "A value name_h3981298716" /d "99" /t REG_DWORD /f
Note that if a value name contains a space then it should be surrounded with double quotes. Keep doing that even if a value name does not contain any space.
Example, with another key name:
==> reg query "HKCU\Software\Test Key" /t reg_dword
End of search: 0 match(es) found.
==> reg add "HKCU\Software\Test Key" /v A value name_h3981298716 /d "99" /t REG_DWORD /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.
==> reg add "HKCU\Software\Test Key" /v "A value name_h3981298716" /d "99" /t REG_DWORD /f
The operation completed successfully.
==> reg query "HKCU\Software\Test Key" /t reg_dword
HKEY_CURRENT_USER\Software\Test Key
A value name_h3981298716 REG_DWORD 0x63
End of search: 1 match(es) found.

Change registry DisableTaskManager not working in Windows 7

I want to disable a standard user from accessing the task manager. With gpedit.msc this works without problems, but I need to do this from the Windows registry. I already tried assigning 1 to the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DiableTaskMgr, but it is not working.
I use a bat file:
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableTaskMgr /t REG_DWORD /d 1 /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableChangePassword /t REG_DWORD /d 1 /f
taskkill /IM explorer.exe /F

Resources