Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1546
  • Last Modified:

reg query command for registry entry

Hi Experts.  I am wanting to include a query command in my login script to detect the presence of an Office 2003 or Office 2007 registry entry on the computer.  I have the reg command but I can't determine how to get the result code 0 (success) or 1 (failure).  What am I missing?

(This login script will be ran on Windows XP pc's)

Looking for HKLM\software\microsoft\office\11.0\outlook or \12.0\outlook

Thanks Experts!
0
samiam41
Asked:
samiam41
  • 22
  • 6
  • 4
  • +1
3 Solutions
 
michael626Commented:
you could use REG QUERY
reg query \\%computername%\HKLM\software\microsoft\office\12.0\Outlook /ve
0
 
samiam41Author Commented:
Thanks for the quick reply!

I am running:
reg query \\pc\hklm\software\microsoft\office\11.0 /f outlook 

which yields ->

End of search: 1 match(es) found

Open in new window


I guess what I am looking for is how to get errorlevel to equal 0 so the next part will kick on.  Other ideas on how to get script to continue if the value is detected are welcome.  :)
0
 
samiam41Author Commented:
So here is my half-thought out code that works for whatever reason.  I say that because I'm not sure "why" it works.

reg query "hklm\software\microsoft\office\11.0" /f outlook | find /i "1"

if %errorlevel% EQU 1 goto notepad
exit

:notepad
notepad.exe

:end
exit

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
samiam41Author Commented:
never mind.  The above code doesn't work.  Getting error levels of 0 and 9009 when I use 11.0 and "error: the system was unable to find the spe....." when I use 12.0
reg query "hklm\software\microsoft\office\11.0" /f outlook | echo %errorlevel%

if %errorlevel% EQU 0 goto notepad
exit

:notepad
notepad.exe

:end
exit

Open in new window

0
 
michael626Commented:
your variable must be cleared if you use it multiple times your last code seems to works
0
 
samiam41Author Commented:
your variable must be cleared if you use it multiple times

Hmm...  Being completely honest with you here, I have no idea what that means.  If there was a level below novice, I'm not even at that level.  :)  I kind of dumb lucked my way through the code above and came out after a lot of trial and error.
0
 
samiam41Author Commented:
Quick search for clearing variable shows to use "set variable=" at the command prompt which I did and then using the command prompt ran the

reg query "hklm\software\microsoft\office\11.0" /f outlook | %errorlevel%

Open in new window

yields a 1 which is what I want (I'm guessing) and will set the if %errorlevel% EQU 1 goto <section1> and will use that section to do an "action".  Is that right?  
0
 
samiam41Author Commented:
Ok.  Hold on.  Before I make this 100x more complicated than it needs to be because of my drastic lack of experience/skillset in this area, would you recommend a different way to find out what value (11.0 or 12.0) of office is in the registry and have the output determine the next action?
0
 
michael626Commented:
what's your goal, i just want to understand if there's an easier way to do that.
0
 
samiam41Author Commented:
Fair enough,

When the user logs in, I would like the login script to query the registry and if the user is on a pc that has Office 2003 (11.0) installed, I need the script to jump down to the Office 2003 section where a set of actions will occur.  If the user has Office 2007 (12.0) installed, the script jumps to that section where a different set of actions occur.

Thoughts?
0
 
michael626Commented:
Set objOutlook = CreateObject("Word.Application")
    Select Case objOutlook.Version
    Case "12.0" MsgBox ("Outlook 2007 is installed")
    Case "11.0" MsgBox ("Outlook 2003 is installed")
    Case "10.0" MsgBox ("Outlook 2002 (XP) is installed")
    Case "9.0" MsgBox ("Outlook 2000 is installed")
    End Select
objOutlook.Quit

in a vbs script but use Word to detected it so not precise at all but working
i took that a modified from this website:
http://www.tek-tips.com/viewthread.cfm?qid=1579439&page=26

I tried Outlook.application and didn't worked for me
0
 
samiam41Author Commented:
Thanks Michael.  I really need it in a batch file so I can make changes to it (I am not familar with vb).

The script should check the registry for the presence of Office 12.0 and if those keys are detected, the script goes to the Office.2007 portion and modifies that portion of the registry.  If the Office 12.0 keys aren't found, then the script goes to the Office 2003 section and modifies that portion of the registry as defined in the script.

I can fill in the the actions of the registry but can't determine how to use a batch file to script the detection.
 
0
 
samiam41Author Commented:
Two super EE brainiacs gave me this part of a script in a previous question.  Perhaps we can build off this?
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
 
Justin OwensITIL Problem ManagerCommented:
Not around a test machine, so use at your own risk:

REG QUERY "HKCU\Software\Microsoft\Office\11.0" >nul 2>nul && (
     ECHO "Office 2003 Detected" 
     GOTO OFFICE2003
) || (
REG QUERY "HKCU\Software\Microsoft\Office\12.0" >nul 2>nul && (
     ECHO "Office 2007 Detected" 
     GOTO OFFICE2007
)

:OFFICE2003
REM Do your Actions here
GOTO BLOB

:OFFICE2007
REM Do your Actions here
GOTO BLOB

:BLOB
REM Continue your Script here

Open in new window


Again, that may be fruitless... It has been a while since I did anything in batch and I have no way to test this today.

DrUltima
0
 
samiam41Author Commented:
Thanks DrUltima.  Testing it now!
0
 
QlemoC++ DeveloperCommented:
Please clarify the following items, as it is unclear now what you ask for exactly:
(a) shall we check HKLM or HKCU?
(b) do you want the lowest installed Office release, or the highest?
      Note: We cannot know which one is the actual one by inspecting HKCU
(c) Outlook and Office don't be necessary the same version.

Issues arise in particular with Office 2003 & the 2007 Compatibility Pack, since that will create both 11.0 and 12.0 keys, and if Outlook/Office has been updated.

DrUltima's batch would work (with restrictions), but I would code it much better :P
0
 
samiam41Author Commented:
Oh Qlemo,  you can start sh*t like no other.  : )

Since I am way out of my league here, I am going to rely on you, DrUltima and any other EE expert to tell me the best way to achieve the end result which is:

I have 200+ users that I am migrating (in phases) from Office 2003 to Office 2007.  During the migration, I have a set of registry entries that I need to have made depending on the version of Office the user has installed.  I thought the best time for this was when the user logs in and the script is triggered but perhaps this should be done in a GPO?

Thoughts/suggestions/constructive criticisms?
0
 
Justin OwensITIL Problem ManagerCommented:
I have no problems with Qlemo writing better code than me. :)  He is much, much better at it.  He isn't starting anything that I probably haven't started with him in other threads, anyway.  ;-)

-DrU
0
 
samiam41Author Commented:
@DrUltima:  Fair enough although I don't know what I am going to do with all of the popcorn I bought to see two titans battle it out...  :)

With all that said, what is the best way to get these registry changes made?  Script, script via GP, reg keys deployed via GP, some other to be mentioned method?  
0
 
Justin OwensITIL Problem ManagerCommented:
What tools do you have at your disposal?  Are all your scripts Batch?  Do you use SCCM?  Are you familiar with using GPO to remove and add software?  I would use a script as a last resort.  My preference would be to use SCCM in this scenario.  There are also third party application management tools (CA's Unicenter Desktop and Server Management Software Delivery, for example), but the good ones tend to be pricey.

DrUltima
0
 
Justin OwensITIL Problem ManagerCommented:
And, I just noticed after re-reading Q's comment that I accidentally used HKCU rather than HKLM.  Sorry about that.

DrU
0
 
samiam41Author Commented:
I'm using LANguard to deploy the Office 2007 software.  Once the software is deployed, the computer restarts (migration stages happen in the evening).  When the user comes in the next morning, I wanted to make sure that the location for their Outlook prf are set, the first run wizard and RSS update feed is disabled to mention just a couple.  I figured the best way to do all of that was via a login script but have since took a quick second to rethink and consult the tech overlords on the best course.  Since the registry keys they would need to modify are HKCU, they would be able to modify their own (correct)?  
0
 
Justin OwensITIL Problem ManagerCommented:
Can LANGuard use an upgrade if the older software is detected, or is it a "one solution" deployment?  Yes, users can generally modify keys under HKCU.

DrUltima
0
 
samiam41Author Commented:
That's a good question.  The best way I can answer that is by saying I am installing Office 2007 software on the computer without uninstalling the existing Office 2003 software that may be installed.  Is that an upgrade?  The LANguard is only deploying the config.xml script that relates to the software package created.  I know you didn't expect a four line answer to a simple question but I can't say for certain if it's a yes or no.

I went ahead and deployed Office 2007 on a virtual pc and since I am confident in your scripting ability, I modified the production login script to include the portion you provided above so I can see how the testing on the virt pc comes out.  :)  Ok, maybe not the production login script but I did have the test user account run this as its login script:

 
:office.2007
REG QUERY "HKCU\Software\Microsoft\Office\12.0" >nul 2>nul && (
     ECHO "Office 2007 Detected" 
     GOTO OFFICE2007
) || (
REG QUERY "HKCU\Software\Microsoft\Office\11.0" >nul 2>nul && (
     ECHO "Office 2003 Detected" 
     GOTO OFFICE2003
)

:OFFICE2007
REM Do your Actions here
reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run
reg delete HKEY_CURRENT_USER\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
GOTO delete.existing.network.drive.mappings

:OFFICE2003
REM Do your Actions here
set OutlookTimeout=10
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "First-Run" /f
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "FirstRun" /f
reg add "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "ImportPRF" /d "\\w2k3fs01\login\outlook.PRF" /f
GOTO delete.existing.network.drive.mappings

Open in new window

0
 
samiam41Author Commented:
D@mn I made that complicated.  Office 2007 is installing OVER the Office 2003 products that are listed in the config.xml list.  Since I have Word 2007 listed, it will install Word 2007 over Word 2003 but I don't have Access 2007 included in the list so if the user (for whatever rare reason) has Access 2003, it stays installed and won't get Access 2007.

Sorry for the long answer.
0
 
Justin OwensITIL Problem ManagerCommented:
And... Did it work as expected?  BTW, you CAN have all apps in the office suite as both 2003 and 2007 EXCEPT Outlook.  Only one version of it can exist on a computer at a time.

DrUltima
0
 
samiam41Author Commented:
When I run the test script (see below) from the command prompt, I am getting to the "goto office.reg.mod" section and then nothing.  I verified the reg entries are not being made.  I did run

reg add "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup" /v "ImportPRF" /d "\\w2k3nas01\public\office.2007\prf\cs.outlook07.PRF" /f

and the reg entry was created without problem.  The script just seems to not process the "office.reg.mod" section.
REM @echo off
REM --=Login Script created by Aaron L. Shaw=--
REM --=Version 11.03.10=--
REM --=\\w2k3fs01\login\login.bat

if Windows_NT == %OS% goto WINNT

:WINNT
ver

ver | find "XP" /C

if not %errorlevel% EQU 0 goto NOTFOUND
goto office.2007

:NOTFOUND
goto exit

:office.2007
REG QUERY "HKCU\Software\Microsoft\Office\12.0" >nul 2>nul && (
     ECHO "Office 2007 Detected" 
     GOTO OFFICE2007
) || (
REG QUERY "HKCU\Software\Microsoft\Office\11.0" >nul 2>nul && (
     ECHO "Office 2003 Detected" 
     GOTO OFFICE2003
)

:OFFICE2007
REM Do your Actions here
reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run
reg delete HKEY_CURRENT_USER\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
GOTO delete.existing.network.drive.mappings

:OFFICE2003
REM Do your Actions here
set OutlookTimeout=10
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "First-Run" /f
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "FirstRun" /f
reg add "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "ImportPRF" /d "\\w2k3fs01\login\outlook.PRF" /f
GOTO delete.existing.network.drive.mappings

:delete.existing.network.drive.mappings
net use i: /delete
net use k: /delete
net use L: /delete
net use m: /delete
net use n: /delete
net use q: /delete
net use s: /delete
net use t: /delete
net use u: /delete

Open in new window

0
 
samiam41Author Commented:
Hold on.  Sorry.  Man this is wearing on me.  Here is the actual copy/paste from the script...
REM @echo off
REM --=Login Script created by Aaron L. Shaw=--
REM --=Version 11.03.10=--
REM --=\\w2k3fs01\login\login.bat

if Windows_NT == %OS% goto WINNT

:WINNT
ver

ver | find "XP" /C

if not %errorlevel% EQU 0 goto NOTFOUND
goto office.reg.mod

:NOTFOUND
goto exit

:office.reg.mod
REG QUERY "HKLM\SOFTWARE\Microsoft\Office\12.0" >nul 2>nul && (
     ECHO "Office 2007 Detected" 
     GOTO OFFICE2007
) || (
REG QUERY "HKLM\Software\Microsoft\Office\11.0" >nul 2>nul && (
     ECHO "Office 2003 Detected" 
     GOTO OFFICE2003
)

:OFFICE2007
REM Do your Actions here

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

reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run
reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\FirstRun


GOTO delete.existing.network.drive.mappings

:OFFICE2003
REM Do your Actions here
set OutlookTimeout=10
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "First-Run" /f
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "FirstRun" /f
reg add "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "ImportPRF" /d "\\w2k3fs01\login\outlook.PRF" /f
GOTO delete.existing.network.drive.mappings

:delete.existing.network.drive.mappings
net use i: /delete
net use k: /delete
net use L: /delete
net use m: /delete
net use n: /delete
net use q: /delete
net use s: /delete
net use t: /delete
net use u: /delete

exit

Open in new window

0
 
samiam41Author Commented:
**SUCCESS**

Made a slight modification in the script and the reg keys were made.

 
REG QUERY "HKLM\SOFTWARE\Microsoft\Office\12.0" | GOTO OFFICE2007
) || (
REG QUERY "HKLM\Software\Microsoft\Office\11.0" | GOTO OFFICE2003
)

Open in new window

0
 
samiam41Author Commented:
LOL!!  My ignorance is amazing at times.  :)

So I did a revert on the virtual pc to see what happens if I run the test script and I'm guessing since I did a horrible hatchet job on the script, it created the reg keys for the 12.0 without even calculating whether or not 12.0 was in the HKLM.  Ugh.  How I found my way to work this morning is a mystery.

Ok.  So back to waiting (patiently) for help since the script I butchered does in fact not work.  Thanks for everyone's help and patience.
0
 
QlemoC++ DeveloperCommented:
Could you post your script again? And then tell what does not work? I'm confused ...
0
 
samiam41Author Commented:
It works.  Man that was a monster!  I took some previous code, mixed in mine and arrived at this which works if Office 2003 is installed or Office 2007 or the compatibility pack for 2007 (which I didn't think of until you mentioned it).


2>nul >nul REG QUERY "HKLM\SOFTWARE\Microsoft\Office\12.0\Outlook" && (

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

reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\First-Run
reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Setup\FirstRun

) || (

set OutlookTimeout=10
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "First-Run" /f
reg delete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "FirstRun" /f
reg add "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup" /v "ImportPRF" /d "\\w2k3fs01\login\outlook.PRF" /f

)

Open in new window

0
 
QlemoC++ DeveloperCommented:
But that script does not work with 2010! :-))
0
 
samiam41Author Commented:
And I will be looking for you and your nemisis, I mean, fellow EE'er DrU to help when that time comes.  hahaha!!

0
 
samiam41Author Commented:
Thanks everyone for putting up with my rambling code, broad question and spam like responses.  No more coffee and alergy medicine.

It was great to work with you all and look forward to doing it again soon!

Thanks,
Aaron
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 22
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now