Add registry from bat file - batch-file

I am trying to add registry entry from bat file. I have a reg file that contains
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Control Panel]
"HomePage"=dword:00000001
It works if you double click the reg file. However, I need to make the same registry edit from bat file. I have tried this
reg add HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel /v HomePage /t REG_DWORD /d 0 /f
But doesnt work. What is the correct way to do that ? (except running .reg file from bat file)

Put quotes around the key name.
reg add "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel" /v HomePage /t REG_DWORD /d 0 /f
Because "Internet Explorer" and "Control Panel" contain spaces, you need quotes so it is all treated as one parameter.

Related

Run registry issue. DELETE script opening folder

I created two scripts, one to delete shortcuts from a folder whenever the system boots up using Run registry and the other to add REG key to Run registry. The problem is whenever I bootup my device it keeps opening the folder location specified in the DELETE Script. Any solution for this guys ? I will share the commands that I used below.
DELETE script :
del /s /q "%Appdata%/Microsoft\Windows\Start Menu\Programs\Startup\*.*"
ADDING REG KEY TO RUN script :
xcopy /s "%~dp0delete.bat" "C:\Program Files\perma\"
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Delete /t REG_EXPAND_SZ /d "C:\Program Files\perma\delete.bat" /f

Why does this bat file not execute properly?

I need to add a subkey in the registry of Windows 10 with a .bat script, but the results are not what is expected. Code does produce a result, but creates an incorrect entry. I need a subkey named EnableLinkedConnections that is of the type: REG_DWORD with a data value of 1
I have already written a .bat to add entries which are correct, but trying to add another in a different registry folder creates an incorrect entry.
#echo off
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\" /f /v "EnableLinkedConnections" /t REG_DWORD d/ 0x1
pause
This creates a folder outside of the System folder, but still in the Policies folder named:
System" /f /v EnableLinkedConnections /t REG_DWORD d/ 0x1
which is not correct. I expected a subkey entry of type REG_DWORD.
Seems that its having an issue with backslashes maybe, but the other .bat I wrote does not do this, so a bit stumped. Any pointers welcome.

Delete files in context menu with bat file windows 8

my bat file:
#echo off
set targetfolder=%1
cd /d %1
del .
pause
my delete.reg file
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script]
#="Delete all"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script\command]
#=C:\delete.bat \"%V\"
The option is in the context menu but if I click Im getting this error:
This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel.
[OK]
You don't really need a batch file, you should be able to run a command directly from the registry key.
Example:
#ECHO OFF
SETLOCAL
SET "SKEY=HKCU\Software\Classes\"
SET "EKEY=\shell\DeleteAll"
REG ADD %SKEY%Folder%EKEY% /VE /D "Delete &All Files" /F>NUL
REG ADD %SKEY%Folder%EKEY%\command /VE /T REG_EXPAND_SZ /D^
"%%COMSPEC%% /C PUSHD %%L && DEL *.*" /F>NUL
Right-click on a folder and select 'Delete All Files' to delete all normal files within that folder. (Be careful this will be catastrophic if you select the wrong folder)

File association using CMD

What are ways to associate file from cmd?
For example,I want .txt file extension to associate with a typical program, through command prompt?
what is the correct file association cmd command?
One needs to use ftype and assoc commands as follows (and note that sequence matters):
ftype txtfile="C:\Program Files (x86)\PSPad editor\PSPad.exe" "%1"
assoc .log=txtfile
assoc .txt=txtfile
assoc .wtx=txtfile
or
ftype TIFImage.Document="C:\Program Files\MSPVIEW.exe" "%1"
assoc .tif=TIFImage.Document
assoc .tiff=TIFImage.Document
Note that I haven't MSPVIEW.exe installed so I can't approve your ftype assignment rightness. In my Windows ftype TIFImage.Document command output is as follows:
TIFImage.Document=%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1
File association with COMMAND PROMPT (using .bat file):
REG ADD "HKEY_CLASSES_ROOT\Applications\notepad++.exe\shell\open\command" /v "" /t REG_SZ /d "\"C:\Program Files\\Notepad++\\notepad++.exe\" \"%%1\"" /f
::or use ---------------> REG ADD "HKEY_CLASSES_ROOT\txtfile\shell\open\command" /v "" /t REG_SZ /d "\"C:\Program Files\\Notepad++\\notepad++.exe\" \"%%1\"" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt" /v "Application" /t REG_SZ /d "notepad++.exe" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList" /v "g" /t REG_SZ /d "notepad++.exe" /f
ftype txtfile="C:\Program Files\Notepad++\notepad++.exe" "%%1"
assoc .txt=txtfile
NOTE! If typing directly in CMD(instead of .bat) then use single % (instead of double %%) and single \ (instead of double \)
The previous suggested solutions are unnecessarily complicated and risky. Just right click on the file, click "Open with" and indicate the App you prefer (flag for permanent replacement). Windows does all this automatically and without risk.

Batch file script lost in translation to exe?

I have this command in my batch script
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "My App" /t REG_SZ /F /D "C:\MyAppPath\MyApp.bat"
and it works as a bat file in windows7 however when convert it to exe file using the command below,
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "My App" /t REG_SZ /F /D "C:\MyAppPath\MyApp.exe"
Using bat to exe converter,iexpress or advanced converter the program does not start at start up? Somehow the function of the bat command is not translated into the exe file?
Thanks guys got it to work by disabling UAC

Resources