We help IT Professionals succeed at work.

What is wrong with this batch script?

648 Views
Last Modified: 2010-05-18
The following script interegates the registry for keys, to determine what new string values need to be created.

REG QUERY "HKLM\Software\Microsoft\Office" /S |Find /I "11.0">nul
IF %ERRORLEVEL% EQU 0 (
      IF EXIST "%APPDATA%\Microsoft\Signatures\Signature.htm" (DEL /Q "%AppData%\Microsoft\Signatures\Signature.htm")
      IF EXIST "%AppData%\Microsoft\Signatures\%USERNAME%.htm" (REN "%AppData%\Microsoft\Signatures\%USERNAME%.htm" Signature.htm)
      SET ERRORLEVEL=
      REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" /S |Find /I "Outlook">nul
      IF %ERRORLEVEL% EQU 0 (
            ECHO %ERRORLEVEL%
            PAUSE
            REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
      ) ELSE (
            SET ERRORLEVEL=
            REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" /S |Find /I "%USERNAME%">nul
            IF %ERRORLEVEL% EQU 0 (
                  REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
            )
      )
)

The problem is despite the key "outlook" not being present in HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles it is still resolving as if it is?

Is there a blatent obvious problem here? I just can't see why its resolving true when its clearly false?!

Many thanks in advance.


Comment
Watch Question

Richard QuadlingSenior Software Developer

Commented:
Try this. I've remmed out the lines I think are wrong and added comments as to why.
REM I've reformatted for my own readability.
 
REM Either 11.0 exists or it doesn't. No need to find all 11.0s
REG QUERY "HKLM\Software\Microsoft\Office\11.0">NUL
IF %ERRORLEVEL% EQU 0 (
	IF EXIST "%APPDATA%\Microsoft\Signatures\Signature.htm" DEL /Q "%AppData%\Microsoft\Signatures\Signature.htm"
	IF EXIST "%AppData%\Microsoft\Signatures\%USERNAME%.htm" REN "%AppData%\Microsoft\Signatures\%USERNAME%.htm" Signature.htm
REM Outlook exists as a value in the Profiles key.
REM      REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" /S |Find /I "Outlook">nul
	REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook">NUL
	IF %ERRORLEVEL% EQU 0 (
		ECHO %ERRORLEVEL%
		PAUSE
		REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
	) ELSE (
		REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%">NUL
		IF %ERRORLEVEL% EQU 0 (
			REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
		)
	)
)

Open in new window

Richard QuadlingSenior Software Developer

Commented:
If I run ...

REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"

I get ...


! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles
    DefaultProfile      REG_SZ  Outlook

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook


As you can see the DefaultProfile exists with a value of Outlook.

If I now use Find on that output ...

    DefaultProfile      REG_SZ  Outlook
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook

And if there was no Outlook key the output would be ...

    DefaultProfile      REG_SZ  Outlook

which is the problem you are facing.


The solution I use it to search directly using ...

REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook"

which outputs ...


! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\0a0d020000000000c000000000000046

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\16d77d2274fe9544b126119cea16ebd2

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\1e12d25ccdb11f43a62bfba3bf319fc9

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\20e8b9b50e941641960d424d1d9060be

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\2f1aec392e49254cae21a5bc4c3c52b8

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\3517490d76624c419a828607e2a54604

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\37d94973ebb5414d974753e3f6793423

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\3bbedbdc8c5df549afdcc812906b1c1d

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\42acdf40ca5b11cdb7ba00aa003cf7f1

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\4dc61134234455438632364607a93b5b

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\5acf76a3665511cea39a00aa004acafa

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\5d20ca5d9526f945bb11f892941a51e6

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\82009bae33c1ed4892d8f579124c171b

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\8503020000000000c000000000000046

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9207f3e0a3b11019908b08002b2a56c2

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\92d9e3733d654d4282dd976b1267e616

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\964e6f1da8fe174d9e7d0f3baa06082f

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\99087144a05d044fbca393360a00bb8c

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\c02ebc5353d9cd11975200aa004ae40e

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\d56f7066d8d1cd4f84674c2a8f2e0844

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\d884b0b4caebe7428dcbc137ffaca61e

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\dca740c8c042101ab4b908002b2fe182

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\eb3877e8d51fd44e858307395f63ef3f

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\f15b3576b65a284788fcf43590cc1f61

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\f6123bb6bcaa8442b97e3f406490491f

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\f86ed2903a4a11cfb57e524153480001


Ok. A load of output, but say I searched for ...

REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\OutlookNotInstalled"

then I get output of ...

Error:  The system was unable to find the specified registry key or value

which also has an errorlevel of 1.

Hope that explains it for you.

Regards,

Richard Quadling.

Antonio KingIT Manager

Author

Commented:
Despite REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook">NUL coming back as "Error: The system was unable to find the specified registry key or value" it is still applying the REG ADD command if the errorlevel is 0.

When the Outlook key clearly does not exist there!
Richard QuadlingSenior Software Developer

Commented:
Can you try this simple batch file.

The output I get is ...

2008/07/08  9:41:25 C:\>doit2

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook

[SNIPPED]

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\f86ed2903a4a11cfb57e524153480001
0

Error:  The system was unable to find the specified registry key or value
1

2008/07/08  9:41:26 C:\>







Another thing to try is to echo the errorlevel immediately after the REG QUERYs. Just to make sure you are getting the right values.



@ECHO OFF
REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook"
ECHO %ERRORLEVEL%
REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Garbage"
ECHO %ERRORLEVEL%

Open in new window

Richard QuadlingSenior Software Developer

Commented:
Hi,

Here is another version with debugging and logging and everything. Run this exactly as is and present the output. The output is the only was I can see what is going on. As far as I can tell, this should work as expected.

My output is (edited) ...

About to look for Office 11.0Press any key to continue . . .REG QUERY to find Office 11.0 returns 0Results of REQ QUERYPress any key to continue . . .! REG.EXE VERSION 3.0HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\AccessHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\CommonHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\DeliveryHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\ExcelHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\MSEHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\OutlookHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\PowerPointHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\RegistrationHKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\WordPress any key to continue . . .About to look for Outlook ProfilePress any key to continue . . .REG QUERY to find the Outlook Profile returns 0Results of REQ QUERYPress any key to continue . . .! REG.EXE VERSION 3.0HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\OutlookHKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\0a0d020000000000c000000000000046[SNIPPED]HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\f86ed2903a4a11cfb57e524153480001Press any key to continue . . .About to add signature.Press any key to continue . . .The operation completed successfullyREG ADD to add signature returns 0Press any key to continue . . .


@ECHO OFF
 
ECHO About to look for Office 11.0
PAUSE
REG QUERY "HKLM\Software\Microsoft\Office\11.0">"%TEMP%\__REG.LOG"
ECHO.
ECHO REG QUERY to find Office 11.0 returns %ERRORLEVEL%
ECHO.
ECHO Results of REQ QUERY
PAUSE
MORE<"%TEMP%\__REG.LOG"
PAUSE
 
IF %ERRORLEVEL% EQU 0 (
 
	IF EXIST "%APPDATA%\Microsoft\Signatures\Signature.htm" DEL /Q "%AppData%\Microsoft\Signatures\Signature.htm"
	IF EXIST "%AppData%\Microsoft\Signatures\%USERNAME%.htm" REN "%AppData%\Microsoft\Signatures\%USERNAME%.htm" Signature.htm
 
	ECHO About to look for Outlook Profile
	PAUSE
	REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook">"%TEMP%\__REG.LOG"
	ECHO.
	ECHO REG QUERY to find the Outlook Profile returns %ERRORLEVEL%
	ECHO.
	ECHO Results of REQ QUERY
	PAUSE
	MORE<"%TEMP%\__REG.LOG"
	PAUSE
 
	IF %ERRORLEVEL% EQU 0 (
 
		ECHO About to add signature.
		PAUSE
		REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
		ECHO.
		ECHO REG ADD to add signature returns %ERRORLEVEL%
		ECHO.
		PAUSE
 
	) ELSE (
 
		ECHO About to find %USERNAME% Profile.
		PAUSE
		REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%">"%TEMP%\__REG.LOG"
		ECHO.
		ECHO REG QUERY to find %USERNAME% Profile returns %ERRORLEVEL%
		ECHO.
		ECHO Results of REQ QUERY
		PAUSE
		MORE<"%TEMP%\__REG.LOG"
		PAUSE
 
		IF %ERRORLEVEL% EQU 0 (
 
			ECHO About to add signature to %USERNAME% Profile.
			PAUSE
			REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
			ECHO.
			ECHO REG ADD to add signature returns %ERRORLEVEL%
			ECHO.
			PAUSE
 
		)
 
	)
 
)

Open in new window

Antonio KingIT Manager

Author

Commented:
There error levels are 0 all the way through.
But when querying the key Outlook it should return false.
I've double checked the registry, the key outlook does NOT exist.
It appears that once the error level is initially set to 0 it won't change within the if statement.

I've tried adding verify>nul to reset the errorlevel, but this causes the script to end abrubtly.
Richard QuadlingSenior Software Developer

Commented:
Please run the script I gave and show me the output.

Without the output of that script I cannot help you.

Please.
Antonio KingIT Manager

Author

Commented:
By the end of the script the __REG.log is empty.
Richard QuadlingSenior Software Developer

Commented:
Can you show me the onscreen output?

Open a cmd prompt.

Run the batch file.

From the icon on the cmd prompt window, choose Edit -> Select All.

When everything is highlighted, press [ENTER].

Come to EE.

Paste into a "snippet".


Antonio KingIT Manager

Author

Commented:

About to look for Office 11.0
Press any key to continue . . .
 
REG QUERY to find Office 11.0 returns 0
 
Results of REQ QUERY
Press any key to continue . . .
 
! REG.EXE VERSION 3.0
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Access
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Common
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Delivery
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Excel
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\MSE
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Outlook
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\PowerPoint
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Publisher
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Registration
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Word
Press any key to continue . . .
About to look for Outlook Profile
Press any key to continue . . .
 
REG QUERY to find the Outlook Profile returns 0
 
Results of REQ QUERY
Press any key to continue . . .
 
! REG.EXE VERSION 3.0
 
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging
 Subsystem\Profiles\Outlook
 
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging
 Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676
Press any key to continue . . .
About to add signature.
Press any key to continue . . .
 
The operation completed successfully
 
REG ADD to add signature returns 0
 
Press any key to continue . . .

Open in new window

Richard QuadlingSenior Software Developer

Commented:
As I see it, that is correct output.

Lines 33 to 48 cover looking for the Outlook profile. It finds it and adds/updates the sig.

I don't see the problem.

Is this a permissions issue?
Antonio KingIT Manager

Author

Commented:
Apologies, I hadn't deleted the outlook key out to test it again... here is the correct snippet

About to look for Office 11.0
Press any key to continue . . .
 
REG QUERY to find Office 11.0 returns 0
 
Results of REQ QUERY
Press any key to continue . . .
 
! REG.EXE VERSION 3.0
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Access
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Common
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Delivery
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Excel
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\MSE
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Outlook
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\PowerPoint
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Publisher
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Registration
 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Word
Press any key to continue . . .
About to look for Outlook Profile
Press any key to continue . . .
 
Error:  The system was unable to find the specified registry key or value
 
REG QUERY to find the Outlook Profile returns 0
 
Results of REQ QUERY
Press any key to continue . . .
Press any key to continue . . .
About to add signature.
Press any key to continue . . .
 
The operation completed successfully
 
REG ADD to add signature returns 0
 
Press any key to continue . . .

Open in new window

Richard QuadlingSenior Software Developer

Commented:
Aha! Now I see the problem. That is really odd. Can you tell me the EXACT key you deleted please?

In my testing, if I look for something that doesn't exist, I get 0.

Maybe you are not running with commandextensions enabled?

Can you try this at the command prompt ..

reg query "HKLM\Junk"
echo %ERRORLEVEL%

I get ...

2008/07/08 13:33:17 C:\>reg query "HKLM\Junk"

Error:  The system was unable to find the specified registry key or value

2008/07/08 13:33:48 C:\>echo %ERRORLEVEL%
1

If you get 0, then I suspect you've not got the extensions enabled.

Try adding this at the top of the batch script (just under the @ECHO OFF) ...

SETLOCAL ENABLEEXTENSIONS



Richard QuadlingSenior Software Developer

Commented:
I get 1 not 0, sorry. Typo. My machine is playing up and I'm going to have to reboot.
Antonio KingIT Manager

Author

Commented:
I've added SETLOCAL ENABLEEXTENSIONS after echo off, still not working correctly.

The key i delete before testing the script is "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\"

So I know, it's not present when the script is querying whether its there or not!

Richard QuadlingSenior Software Developer

Commented:
Aha!

I finally get the same result.

And a working and now tested version.

Don't ask me why it didn't work before I don't know.


@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
 
ECHO About to look for Office 11.0
PAUSE
REG QUERY "HKLM\Software\Microsoft\Office\11.0">"%TEMP%\__REG.LOG"
IF ERRORLEVEL 1 GOTO Failed1
 
ECHO.
ECHO REG QUERY to find Office 11.0 returns %ERRORLEVEL%
ECHO.
ECHO Results of REQ QUERY
PAUSE
MORE<"%TEMP%\__REG.LOG"
PAUSE
 
IF EXIST "%APPDATA%\Microsoft\Signatures\Signature.htm" DEL /Q "%AppData%\Microsoft\Signatures\Signature.htm"
IF EXIST "%AppData%\Microsoft\Signatures\%USERNAME%.htm" REN "%AppData%\Microsoft\Signatures\%USERNAME%.htm" Signature.htm
 
ECHO About to look for Outlook Profile
PAUSE
REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\" /ve >"%TEMP%\__REG.LOG"
IF ERRORLEVEL 1 GOTO Try2
 
ECHO.
ECHO REG QUERY to find the Outlook Profile returns %ERRORLEVEL%
ECHO.
ECHO Results of REQ QUERY
PAUSE
MORE<"%TEMP%\__REG.LOG"
PAUSE
 
ECHO About to add signature.
PAUSE
REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
ECHO.
ECHO REG ADD to add signature returns %ERRORLEVEL%
ECHO.
PAUSE
GOTO :EOF
 
:Try2
ECHO About to find %USERNAME% Profile.
PAUSE
REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%">"%TEMP%\__REG.LOG"
IF ERRORLEVEL 1 GOTO Failed2
 
ECHO.
ECHO REG QUERY to find %USERNAME% Profile returns %ERRORLEVEL%
ECHO.
ECHO Results of REQ QUERY
PAUSE
MORE<"%TEMP%\__REG.LOG"
PAUSE
 
ECHO About to add signature to %USERNAME% Profile.
PAUSE
REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%USERNAME%\9375CFF0413111d3B88A00104B2A6676\00000001" /V "New Signature" /T REG_BINARY /D 5300690067006e00610074007500720065000000 /f
ECHO.
ECHO REG ADD to add signature returns %ERRORLEVEL%
ECHO.
PAUSE
GOTO :EOF
 
:Failed1
ECHO Failed to find Office 11.0
GOTO :EOF
 
:Failed2
ECHO Failed to find %USERNAME% profile.
GOTO :EOF

Open in new window

Senior Software Developer
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Antonio KingIT Manager

Author

Commented:
Wahey! Think we both learnt something new today, Errorlevels can't be used more than once in the same IF statement. How bizarre.

Thank you very much for your help and patience.
Richard QuadlingSenior Software Developer

Commented:
I'm glad to have helped. I must admit I use %ERRORLEVEL% a LOT and inside nested FOR loops. With no trouble. This one though ... completely through me.

The solution is a solution, but not exactly elegant.

Thanks for the points.

Richard.
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.