MS-DOS bat file - regedit seeting

Posted on 2007-12-04
Medium Priority
Last Modified: 2008-02-01
Hi all,

I wrote a .bat file which does the below settings automatically and it works fine.

.bat file looks like the below.
REG DELETE "HKLM\Software\Classes\Excel.Sheet.8" /f /v BrowserFlags
REG ADD "HKLM\Software\Classes\Excel.Sheet.8" /v BrowserFlags /t REG_DWORD /d 0
NET USE X: \\server\directory /y

It does the following automatically:
1. Start Registry Editor (Regedt32.exe).
2. Locate and then click the following registry key:
3. After you identify the subkey for the specific Office document type,
   add the following value for all subkeys
   Value name: BrowserFlags
   Data type: REG_DWORD
   Value: 8
4. Click OK, and then quit Registry Editor.

I want to add some condition to this bat file.
That is if the above regedit setting already exists, do not do anything. Simply exit.
Also if a specific (say X:) map drive already exists, I wan to skip that too.

Is it possible?

Question by:aarch1
  • 2
  • 2
LVL 26

Assisted Solution

souseran earned 150 total points
ID: 20405218
The IF command would be the thing you want. It performs conditional processing in batch programs. More information on it can be found here:


Applied to your batch file:

If exist "HKLM\Software\Classes\Excel.Sheet.8" /f /v BrowserFlags
REG DELETE "HKLM\Software\Classes\Excel.Sheet.8" /f /v BrowserFlags
REG ADD "HKLM\Software\Classes\Excel.Sheet.8" /v BrowserFlags /t REG_DWORD /d 0
else goto [SHARE]


If exist X: go to END else

NET USE X: \\server\directory /y


It's been a while since I've written batch files, so check my syntax, but that's the gist of it.

LVL 86

Accepted Solution

oBdA earned 1350 total points
ID: 20405524
Querying for the registry key to be set before changing it doesn't save a lot of time; you can just set it everytime.
You don't need to delete it first, though; just overwrite it (just add the /f in the "reg add" line).
As far as the network mapping is concerned, you should check if X: is mapped to the *correct* share, not only whether it exists.

- Labels in batch begin with a colon.
- "if exist" only works for files, not for registry keys ("help if" for details)
- if and else have to be on the same line in batch ("help if" for details)

reg add "HKLM\Software\Classes\Excel.Sheet.8" /v BrowserFlags /t REG_DWORD /d 0 /f
net use X: | find /i "\\server\directory" >NUL
if errorlevel 1 (
  net use X: /delete
  net use X: \\server\directory /persistent:yes

Open in new window

LVL 26

Expert Comment

ID: 20406487

Thanks for the correction. As I said, it's been a while. :-)


Author Comment

ID: 20408702

Perfect. Thanks for the quick response.

One more question though.
When I run this .bat file from browser, it shows the popup with run, save, cancel button.
After clicking the run button, this .bat runs.

Is there a way to always run the .bat file without this pop?

Your thoughts?

LVL 86

Assisted Solution

oBdA earned 1350 total points
ID: 20409909
You need to add the server on which the batch is stored to the Local Intranet sites in the Internet Explorer settings.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension . This reminded me of questions that come up here at EE along the lines of, "How can I tell the type of file from its cont…
I was recently poking around with LibreOffice and figured out how easy it is to add great vector clip art to one's own LibreOffice gallery collection.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question