Solved

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

Posted on 2010-11-08
16
869 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.
0
Comment
Question by:samiam41
[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
  • 9
  • 4
  • 2
  • +1
16 Comments
 
LVL 14

Expert Comment

by:athomsfere
ID: 34086443
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.
0
 
LVL 31

Assisted Solution

by:Justin Owens
Justin Owens earned 75 total points
ID: 34086504
In Batch, there is no "ELSE" in IF statements.  Your IF includes the selected parameters, and then it goes on.  If it doesn't meet the parameters, it just goes on.  You will need to manipulate it differently, though.  IF you want to check for the existence of a registry key and delete a specif key if it does exist, try this:

REG QUERY "HKCU\Software\Microsoft\Office\12.0" || REG DELETE "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run"

Remember that the Registry is Case SeNsItIvE.  HKCU\Software is different than HKCU\software.  Additionally, I would avoid using an IF statement in dealing with registry manipulation.

Justin
0
 
LVL 9

Author Comment

by:samiam41
ID: 34086523
@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?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 9

Author Comment

by:samiam41
ID: 34086568
I ask because there are several mods to the registry I need to make following the Office 2007 install.
0
 
LVL 31

Expert Comment

by:Justin Owens
ID: 34086698
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
0
 
LVL 9

Author Comment

by:samiam41
ID: 34086928
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.
0
 
LVL 31

Expert Comment

by:Justin Owens
ID: 34087010
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.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 425 total points
ID: 34091092
DrUltima,
In Batch, IF with ELSE is available:
if not exist ThisFile.Reg (echo yes) else (echo no)
or, if we have to check for the result of a command:
reg query HKCU\Software >nul 2>nul && (echo Key exists) || (echo Key not available)

samiam41,
I agree to the "brute force delete" method. I would just check for the First-Run key (similar to what DrUltima showed), and then do a lot of things:
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 ...
) || (
  REM anything to do if the key is already deleted, which usually is - nothing
)

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 34093500
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

0
 
LVL 31

Expert Comment

by:Justin Owens
ID: 34093511
Qlemo,

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

Justin
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 34094729
Samiam,
That should do. You can remove the part starting with ||, since you do nothing in case the key is not found (anymore).
0
 
LVL 9

Author Comment

by:samiam41
ID: 34227889
Thanks everyone.  Wrapping this question up in the morning.  I appreciate your patience and help with this.
0
 
LVL 9

Author Comment

by:samiam41
ID: 34288284
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.  
0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 34522168
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
0
 
LVL 9

Author Comment

by:samiam41
ID: 34766639
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.

http://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!
0
 
LVL 9

Author Comment

by:samiam41
ID: 35461999
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.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_26970766.html#a35461977
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

736 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