# [SOLVED] Formatting for REG ADD in a batch file.



## mjmetal (Nov 22, 2009)

I am trying to write batch file for a very specific purpose. All of it seems to work except for the very last step. In the system registry the key

HKCR\exefile\shell\open\command

the default key should be set to 

(Default) Reg_SZ "%1" %* 

if it is not it will not properly open exe files. the same goes for the batfile key and the comfile key respectively. Anyway.

if i go to the command prompt (with administrator privileges) and type in

reg add HKEY_CLASSES_ROOT\exefile\shell\open\command /ve /d "\"%1\" %*\"

it will successfully make the change to the registry. However, if I instruct my .bat file to do the same thing. It writes "" " to the value not fixing the problem at all. At first I thought it was a formatting issue, but in theory should it not work the same in a .bat file as it does if I am typing it, since all a .bat file is essentially is a line-by-line instruction of commands.

Please help... Also if I make a .reg file that looks like this

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell\open\command]
"IsolatedCommand"="\"%1\" %*"
@="\"%1\" %*"

it also works but subbing in that value to the batch file does the same thing. again though, typing it will still work.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Formatting for REG ADD in a batch file.*

Hi - 

Please show me the exact contents of the batch file - place it in code boxes - 


```
[PLAIN][code]

  ****place your code here ****
****place your code here ****
****place your code here ****
****place your code here ****
```
[/PLAIN][/code]

The primary problem you are facing is the % sign - in batch files %% must be used, depending on what you are doing. Any FOR loops involved here?

Also - what is the purpose of this?

Regards. . .

jcgriff2

.


----------



## mjmetal (Nov 22, 2009)

*Re: Formatting for REG ADD in a batch file.*

In my line of work I have noticed that with a VAST majority of the virus removals (mostly in the case of rogue security products) it leaves the operating system incapable of opening exe files. I have made .reg files for the issue, and know how to do it through the command prompt, now I wish to make a batch file that I can run that will clear these commonly altered keys and replace them with the correct values.


```
[PLAIN][code]
@Echo off

reg delete HKEY_CLASSES_ROOT\.exe /ve /f
reg add HKEY_CLASSES_ROOT\.exe /ve /d exefile /f

reg delete HKEY_CLASSES_ROOT\exefile /ve /f
reg add HKEY_CLASSES_ROOT\exefile /ve /d Application /f

reg delete HKEY_CLASSES_ROOT\exefile\shell\open\command /ve /f
reg add HKEY_CLASSES_ROOT\exefile\shell\open\command /ve /d "\"%1\" %*\" /f
```
[/PLAIN][/code]


----------



## mjmetal (Nov 22, 2009)

*Re: Formatting for REG ADD in a batch file.*

mind you that is not what the final contents of the batchfile will be. but mostly what will be going on around it is simple "echo"ing to the user what is happening and a reg export HKCR backup.reg at the beginning. I just copied that out of the document I had open, so if it looked light, thats why


----------



## mjmetal (Nov 22, 2009)

*Re: Formatting for REG ADD in a batch file.*

Yep, switching it to %% in all applicable places worked, and removing the last \ before the last quotation mark fixed the issue, thank you very much, you have no idea how crazy that was driving me. Now to build the rest of it. Thanks much


----------



## jcgriff2 (Sep 30, 2007)

*Re: Formatting for REG ADD in a batch file.*

Hi - 

Glad that worked for you.

Believe me, I know how frustrating it can be to work with batch files - especially when you can get the command to run on the command line itself. Batch scripting is just a little different.

However, to restore execution of EXE files, this is what you need - it's a REG file that can be executed via batch - 

```
[FONT=Lucida Console]
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.EXE]
@="exefile"
"Content Type"="application/x-msdownload"

[HKEY_CLASSES_ROOT\.EXE\PersistentHandler]
@="{098f2470-bae0-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\exefile]
@="Application"
"EditFlags"=hex:38,07,00,00
"FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
  00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,\
  32,00,5c,00,73,00,68,00,65,00,6c,00,6c,00,33,00,32,00,2e,00,64,00,6c,00,6c,\
  00,2c,00,2d,00,31,00,30,00,31,00,35,00,36,00,00,00

[HKEY_CLASSES_ROOT\exefile\DefaultIcon]
@="%1"

[HKEY_CLASSES_ROOT\exefile\shell]

[HKEY_CLASSES_ROOT\exefile\shell\open]
"EditFlags"=hex:00,00,00,00

[HKEY_CLASSES_ROOT\exefile\shell\open\command]
@="\"%1\" %*"
"IsolatedCommand"="\"%1\" %*"

[HKEY_CLASSES_ROOT\exefile\shell\runas]

[HKEY_CLASSES_ROOT\exefile\shell\runas\command]
@="\"%1\" %*"
"IsolatedCommand"="\"%1\" %*"

[HKEY_CLASSES_ROOT\exefile\shellex]

[HKEY_CLASSES_ROOT\exefile\shellex\DropHandler]
@="{86C86720-42A0-1069-A2E8-08002B30309D}"

[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.exe\UserChoice]

[/FONT]
```
You can find it and other file associtation fixes --> http://www.winhelponline.com/articles/105/1/File-association-fixes-for-Windows-Vista.html


Here is one little batch script that I wrote as I found that IE8's *inetcpl.cpl* is at best selective and I like ALL temp Internet files deleted. Try this one out to delete the temporary Internet files found in the IE5.CONTENT directories - Run it at elevated Admin level (RIGHT-click, run as admin) - 

```
[FONT=Lucida Console]
@echo off

rem	Delete temp ie5.content files

rem	Author: jcgriff2 - J. C. Griffith, Microsoft MVP
rem	(c) March 2010 - New Jersey, California, USA

set "jcgriff1=%localappdata%\Microsoft\Windows\Temporary Internet Files\Content.IE5"
set "jcgriff2=%localappdata%\Microsoft\Windows\Temporary Internet Files\low\content.ie5"

for /f "tokens=*" %%a in ('dir /b /ad "%jcgriff1%"') do (
	del "%jcgriff1%\%%a\*.*" /s /f /q > "%temp%\jcgriff2_ie5"
)
for /f "tokens=*" %%a in ('dir /b /ad "%jcgriff2%"') do (
	del "%jcgriff2%\%%a\*.*" /s /f /q >> "%temp%\jcgriff2_ie5" 
)
start notepad "%temp%\jcgriff2_ie5" 
goto EOF
:EOF
exit[/FONT]
```
`

Happy scripting!

Regards. . .

jcgriff2

.


----------

