We help IT Professionals succeed at work.

login batch script to modify reg if certain reg file exist on pc

913 Views
Last Modified: 2012-05-10
Hi Experts.  As I upgrade these Windows XP machines from Office 2003 to 2007, I need to modify the registry on the upgraded pc's.  I don't know the term to use for the login script to modify the registry only if the Office 12.0 reg entry is there.  This is what I have:

if exist "hkcu\software\microsoft\office\12.0"
reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run

I'm not sure how to specify what to do if that reg file does "not" exist.  How can I specify if exist, do A; if entry doesn't exist, do B?

Thanks in advance.
Comment
Watch Question

Is it a do nothing id does not exist?

Batch is different then a true language, where in VB or JS you would normally write something like:

If <condition> then {
do something
}
else {
Do nothing
}
end if

Batch, you can write:

If exist <value> do (<something>)

You are not required to write an else or else if, if nothing else is needed.
Justin OwensITIL Problem Manager
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
@athomsfere: thanks for the quick response and information/explanation.  

@drultima:  Great call on the reg query part.  I would have pulled out what remaining hair I had left on diagnosing why it wasn't running.  After reading the last line of your response, you would suggest modifying the registry differently than the way I had planned?

Author

Commented:
I ask because there are several mods to the registry I need to make following the Office 2007 install.
Justin OwensITIL Problem Manager

Commented:
Well, if you don't want to use VB, I would honestly write a batch file to run at the end of the upgrade to just delete the keys you are needing deleted rather than querying everything.  You know they will probably be there, right?

Justin

Author

Commented:
The office 2007 deployment is being managed by LANguard and I don't see where I can configure a batch file to run following the deployment.
Justin OwensITIL Problem Manager

Commented:
I am unfamiliar with LANguard.  Could you use it to deploy a flag file (empty text file) to search for?  Then, you could use your IF EXIST clause to look for that text file (though, I would do a IF NOT EXIST "filename" GOTO END instead) and run your changes at that point.
"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the suggestions.  Great work!

Looking through LANguard, I don't see an option to run a batch file after the Office 2007 install is finished.  The best option I would have is to get the user when they log in.  That said, what would the portion of code look like that I would insert into the existing login script?  I added a couple lines of code representing registry entries that needed to be "added" as well.


2>nul >nul reg query "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run" && (
  reg delete "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run"
  reg delete "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\FirstRun"
  reg add "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup" /v "ImportPRF" /d "\\w2k3nas01\public\office.2007\prf\cs.outlook07.PRF" /f
  reg add "HKCU\Software\Microsoft\Office\12.0\Common\General" /v "ShownOptIn" /t reg_dword /d 0x1 /f
  reg add "HKCU\Software\Microsoft\Office\12.0\Outlook\Search" /v "DisableDownloadSearchPrompt" /t reg_dword /d 0x1 /f
  reg add "HKCU\Software\Microsoft\Office\12.0\Outlook\Options\RSS" /v "SyncToSysCFL" /t reg_dword /d 0x0 /f
) || (
  REM anything to do if the key is already deleted, which usually is - nothing
) 

Open in new window

Justin OwensITIL Problem Manager

Commented:
Qlemo,

You are right.  It has been so long since I wrote anything in batch I am apparently getting rusty.  Thanks for clarifying.

Justin
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Samiam,
That should do. You can remove the part starting with ||, since you do nothing in case the key is not found (anymore).

Author

Commented:
Thanks everyone.  Wrapping this question up in the morning.  I appreciate your patience and help with this.

Author

Commented:
Ok.  I finally got the LANguard software working again after the app took an e-nap.  Now that the server (and software) are working, I will test this script out and if the e-Gods are willing, I should be able to close the question out and award points.  Thank you all for your help and patience.  

Author

Commented:
Great work and thanks for the help!  Sorry it took so long to finish out but my appreciation remains.  I look forward to working with you all again!

Take care,
Aaron

Author

Commented:
Hi everyone!  Hope the new year has started well for everyone.

if anyone is interested in earning some more points, I posted a question here.

https://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_26787868.html

I created a new one instead of adding it on here since who doesn't like points for their hardwork?

Thanks experts!

Author

Commented:
Hi again.  if anyone is looking to grab up 2000 points on an easy (easy meaning for you) question, please check out this link.  Thanks in advance.  Also, rather than reading through the entire question and thread, I wrote a summary of the question in the very last comment box.

https://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_26970766.html#a35461977
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.