Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS-DOS bat file - regedit seeting

Posted on 2007-12-04
5
Medium Priority
?
4,485 Views
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:
   HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Sheet.5
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.
-----------------------------

Question:
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?

Thanks
0
Comment
Question by:aarch1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 26

Assisted Solution

by:souseran
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:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true

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]

[SHARE]

If exist X: go to END else

NET USE X: \\server\directory /y

[END]

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

0
 
LVL 85

Accepted Solution

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

souseran,
- 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

0
 
LVL 26

Expert Comment

by:souseran
ID: 20406487
@oBdA,

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

souseran
0
 

Author Comment

by:aarch1
ID: 20408702
oBdA:

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?

Thanks
0
 
LVL 85

Assisted Solution

by:oBdA
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.
0

Featured Post

Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

660 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