Solved

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

Posted on 2010-11-08
16
866 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
  • 9
  • 4
  • 2
  • +1
16 Comments
 
LVL 14

Expert Comment

by:athomsfere
Comment Utility
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:DrUltima
DrUltima earned 75 total points
Comment Utility
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
Comment Utility
@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
 
LVL 9

Author Comment

by:samiam41
Comment Utility
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:DrUltima
Comment Utility
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
Comment Utility
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:DrUltima
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 425 total points
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Author Comment

by:samiam41
Comment Utility
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:DrUltima
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
Thanks everyone.  Wrapping this question up in the morning.  I appreciate your patience and help with this.
0
 
LVL 9

Author Comment

by:samiam41
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now