# Solved: How to write a batch file to amend a registry key??



## lpool1

Hi All,

Can any1 help me on writing a batch file for Windows XP which will amend the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\SafeMode\Components\DeskHtmlVersion

I have never written a batch file before, however I have had a try and it doesn't work. The details of my file are below:

REM -----Fix Active Desktop-----
Windows Registry Editor Version 5.00
regedit.exe /s "%USERPROFILE%\Desktop\Keith.reg"
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components]
"DeskHtmlVersion"=dword:00000000
"DeskHtmlMinorVersion"=dword:00000005
"Settings"=dword:00000001
"GeneralFlags"=dword:00000001

I need to change the value data in the key from Decimal 272 to 0.

Thanks,
lpool1


----------



## andythepandy

Hi,
The Windows Registry Editor Version 5.00 part is only needed if you are making a .reg file.
Try this instead:


Code:


REM -----Fix Active Desktop-----

reg add HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components /v DeskHtmlVersion /t REG_DWORD /d "WHATEVER YOU WANT TO CHANGE IT TO"

That will ask for confirmation to overwrite existing values, to skip that add /f to the end of reg add line.

Andy


----------



## lpool1

Hi Andy,

I tried this and it said there are too many command line parameters . Any other suggestions?

Thanks,
Lpool1


----------



## andythepandy

Sorry, I completely forgot: The path to the registry key has to be in quotes if it has spaces 

Andy


----------



## lpool1

Thanks Andy,

This time it said the operation was completed successfully, however when I go into regedit and check the value, it still says 272. I think maybe the best thing is to test this on a PC which has the active desktop message.


----------



## andythepandy

Don't know if this will be the problem, but the code I wrote in my last post changed the value of DeskHtmlVersion in:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components\

where you said you wanted to change it in:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\SafeMode\Components\

Change the path file in the bat file to that and it may do the trick
Just a thought


----------



## lpool1

No the first one was actually correct. It just doesn't change the value .


----------



## andythepandy

Have you refreshed the regedit window with F5?


----------



## lpool1

yep, tried that. still the same. It is definately doing something cos it says operation successful. I just dont know what exactly.


----------



## andythepandy

What happens if you go into command prompt(Start>Run>cmd.exe) and type:


Code:


reg query "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components"

What is the value for DeskHtmlVersion?


----------



## lpool1

The following appeared:

! REG.EXE VERSION 3.0
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components
DeskHtmlVersion REG_DWORD 0x110
DeskHtmlMinorVersion REG_DWORD 0x5
Settings REG_DWORD 0x1
GeneralFlags REG_DWORD 0x1
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components\0


----------



## andythepandy

Then I really don't have a clue what's happening and can't think of anything else to try!
Sorry!


----------



## TheOutcaste

If you misplaced the end quote, or left it off, it won't change the value, but will instead add a new key
This will not work:


Code:


Reg Add "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components /V DeskHtmlVersion /T REG_DWORD /D 0 /F[COLOR=Red][B]"[/B][/COLOR]

If you use that, it will add a new key named *Components /V DeskHtmlVersion /T REG_DWORD /D 0 /F*

It has to be like this:


Code:


Reg Add "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components[COLOR=Red][B]"[/B][/COLOR] /V DeskHtmlVersion /T REG_DWORD /D 0 /F

Let's see if that's what happened.
Copy the text in the following code block into Notepad.
Save it on the desktop as *Query.cmd*. Be sure to change the *Save as Type:* box to *All Files* when saving.


Code:


[plain]Set _file=%userprofile%\Desktop\Query.txt
 >"%_file%" Echo.[CODE]
>>"%_file%" 2>&1 Reg Query "HKCU\Software\Microsoft\Internet Explorer\Desktop" /S
>>"%_file%" Echo.

Start Notepad "%_file%"
Exit[/plain][/code]Double click the file to run it. It will create a file named *Query.txt* on the Desktop and open it in Notepad. Copy and paste the text into your next reply.


----------



## lpool1

I got the following:



Code:


! REG.EXE VERSION 3.0
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components
    DeskHtmlVersion REG_DWORD 0x110
    DeskHtmlMinorVersion REG_DWORD 0x5
    Settings REG_DWORD 0x1
    GeneralFlags REG_DWORD 0x1
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components\0
    Source REG_SZ About:Home
    SubscribedURL REG_SZ About:Home
    FriendlyName REG_SZ My Current Home Page
    Flags REG_DWORD 0x2
    Position REG_BINARY 2C0000002C01000000000000D4030000A2030000000000000100000001000000010000000000000000000000
    CurrentState REG_DWORD 0x40000004
    OriginalStateInfo REG_BINARY 18000000FFFF0000FFFF0000FFFFFFFFFFFFFFFF04000000
    RestoredStateInfo REG_BINARY 18000000D00300001F000000200100001601000001000000
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components /v DeskHtmlVersion /t REG_DWORD /d 0
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components /v DeskHtmlVersion /t REG_DWORD /d 0x00000000
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General
    BackupWallpaper REG_EXPAND_SZ 
    ComponentsPositioned REG_DWORD 0x1
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Old WorkAreas
    NoOfOldWorkAreas REG_DWORD 0x1
    OldWorkAreaRects REG_BINARY 000000000000000000050000A2030000
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\SafeMode
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\SafeMode\General
    Wallpaper REG_EXPAND_SZ %SystemRoot%\Web\SafeMode.htt
    VisitGallery REG_DWORD 0x0
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Scheme
    Edit REG_SZ 
    Display REG_SZ


----------



## andythepandy

That's whats happened isn't it! What the OutCaste said


Code:


reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components" /v DeskHtmlVersion /t REG_DWORD /d "0"

You want the closing quote mark where it is above, not at the very end of the line


----------



## lpool1

That's worked andy  thanks for your help. My mistake with the quotations. There is an option in the command prompt to overwrite the existing file. Is there something I can add to the code to automatically approve?

Lpool1


----------



## andythepandy

yes, just stick /f at the end of the line like:


Code:


reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components" /v DeskHtmlVersion /t REG_DWORD /d "0" /f


----------



## Squashman

Good Job OutCaste


----------



## TheOutcaste

Don't forget to delete those two erroneous keys. You can do it from the Registry Editor, or the command line.
Copy and paste these two lines into the Command Prompt, then press *Enter* (you can paste them both at once)


Code:


Reg Delete "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components /v DeskHtmlVersion /t REG_DWORD /d 0" /F
Reg Delete "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components /v DeskHtmlVersion /t REG_DWORD /d 0x00000000" /F

To paste into the Command Prompt, right click the Window, click *Paste*. If Quick Edit is enabled, the right click will paste immediately.


----------

