1

I have a batch script that does reporting on our systems and part of it queries the registry for information. The script fails to get the key's value when its ran by the system, but whenever I run the script myself, it works perfectly

the command:

REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\ScanMail for Exchange\CurrentVersion" /v PatternStringFormatted > current1.tmp

should return:

HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\ScanMail for Exchange\CurrentVersion
    PatternStringFormatted    REG_SZ    6.645.00

This script is failing on a Server 2008 R2 machine, but runs fine on Server 2003 R2 machines.

Fitz
  • 21
  • 2

2 Answers2

1

The reg command is just a part of the command interpreter you happen to be running. On the x64 version of Server 2008, there are two possible command interpreters your script could be running as:

  • %windir%\System32\cmd.exe
  • %windir%\SysWOW64\cmd.exe

Ironically, the copy in System32 is actually the 64-bit binary and the copy in SysWOW64 is a 32-bit binary. If your script happens to be running within the context of the 32-bit command interpreter, then yes, your reg commands will only have access to the redirected 32-bit registry keys. But if you run it the 64-bit command interpreter, it'll have access to all the 64-bit keys just like any other 64-bit app.

I'm guessing that the automated process you have triggering your script is, itself, a 32-bit process. So when it goes to invoke the command prompt, Windows gives it the 32-bit version of the command prompt. Thus, your script only has access to the 32-bit keys.

Ryan Bolger
  • 16,472
  • 3
  • 40
  • 59
1

Turns out its a problem with the reg command and 64 vs 32 bit keys. Reg queries the 32 bit key, but that information isn't copied from the 64 bit one.

Looks like this script needs to be updated to powershell

Fitz
  • 21
  • 2
  • Reg only queries the 32-bit key if it's being run by the 32-bit version of cmd.exe. You need to have your script run in the 64-bit version. – Ryan Bolger Nov 25 '09 at 17:39