2

I need to release some very old software to work with Windows 7 (X86 and X64). My only compatibility issue is the registration of 4 .ocx files. I have written the following batch file to register based on system architecture.

 @echo off
 setlocal enableextensions
 set REGSVR= 
 if defined PROCESSOR_ARCHITEW6432 (
 set REGSVR=%SystemRoot%\system32\regsvr32.exe
 ) else (
     set REGSVR=%SystemRoot%\SysWOW64\regsvr32.exe
 )
 if defined PROCESSOR_ARCHITEW6432 (
     %REGSVR% /s "C:\Windows\System32\mswinsck.ocx"
     %REGSVR% /s "C:\Windows\System32\Timgctrlv6.ocx"
     %REGSVR% /s "C:\Windows\System32\Graphic.ocx"
     %REGSVR% /s "C:\Windows\System32\mscomctl.ocx"
 ) else (
     %REGSVR% /s "c:\windows\sysWOW64\mswinsck.ocx"
     %REGSVR% /s "c:\windows\sysWOW64\Timgctrlv6.ocx"
     %REGSVR% /s "c:\windows\sysWOW64\Graphic.ocx"
     %REGSVR% /s "c:\windows\sysWOW64\mscomctl.ocx"
 )

This works beautifully in 64 bit Windows 7 by running the batch file as admin. However in my 32 bit Windows 7 test environment it requires me to first disable the UAC prior to running the batch file or it has no affect (even if I right-click and "Run as Admin"). Can someone shed light on how this could be, or possibly how to do this so that I do not have to stipulate to our customers to disable UAC "only for Win 7 32 bit"?

willkk
  • 121
  • 3
  • 14
  • What is `PROCESSOR_ARCHITEW6432`? You might have better luck testing for `if defined PROGRAMFILES(x86)`. You might also benefit from having your script [prompt for elevation if needed](http://stackoverflow.com/q/1894967/1683264). – rojo Feb 09 '15 at 19:08
  • Next environment variables could be relevant to test: `if defined ProgramFiles(x86)` and/or `if defined ProgramW6432` @rojo (that `PROCESSOR_ARCHITEW6432` is a keying mistake IMHO). – JosefZ Feb 09 '15 at 23:04
  • @rojo this is a pretty decent explanation: http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx. I know there are tons of ways to detect bitness but my concern is with he fact that my UAC seems to only need turning off on the Win 7 32 bit system. – willkk Feb 10 '15 at 15:17
  • Ah. Makes sense. I have UAC turned off and my cmd prompt is always run as administrator. (I have learned NOTHING from Linux + sudo.) :) Does regsvr32 set ERRORLEVEL on fail? Maybe you could attempt `%regsvr% /s ocxfile || prompt for elevation`. Need me to elaborate in an answer? – rojo Feb 10 '15 at 15:24

0 Answers0