views:

2245

answers:

3

Hi guys me again :) I have a problem with a batch file I wrote. It works fine on 32-bit, but apparently it doesn't work on 64-bit systems, and I don't know why because I do not have access to a 64-bit system.

This is the code that works on Vista 32-bit system

    @echo off
Set Reg.Key=HKLM\SOFTWARE\Malwarebytes' Anti-Malware
  Set Reg.Val=InstallPath
  For /F "Tokens=2*" %%A In (
   'Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"'
  ) Do Call Set MBAMPATH=%%B

Can someone re-write it to work on a 64-bit please?

Thanks always :)

A: 

First of all there is nothing I know which would be different for batch files on 64-bit Windows compared to 32 bit.

You might try removing echo off from the start to see which line produces which error message (assuming you see any).

However, maybe something clashes with the apostrophes you have used in the for loop. You could try changing it to

for /f "usebackq tokens=2*" %%A in (`Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"`) Do Call Set MBAMPATH=%%B

And while we're at it. Why do you call set there? That isn't necessary, so you could remove it as well:

... do set MBAMPATH=%%B
Joey
Apparently it has somethin' to do with installing MBAM on a 64bit OS, it is installed in the "Program Files (x86)" folder. That it was my mate said to me, he is on a 64-bit OS, and is gettin' errors in the script. The key for MBAM is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Malwarebytes' Anti-MalwareBut me just changing the line on the file to that reg key doesn't seem to work for him either, the installpath is not set to the variable.
A: 

I thought this would work, but still doesn't work on 64-bit. My mate told me that is where the key is in the registry on his 64-bit machine.

@echo off
if %processor_architecture%=="x86" goto EIGHTSIX
if %processor_architecture%=="x64" goto SIXFOUR

:EIGHTSIX
Set Reg.Key=HKLM\SOFTWARE\Malwarebytes' Anti-Malware
  Set Reg.Val=InstallPath
  For /F "Tokens=2*" %%A In (
   'Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"'
  ) Do Call Set MBAMPATH=%%B


:SIXFOUR
Set Reg.Key=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Malwarebytes' Anti-Malware
  Set Reg.Val=InstallPath
  For /F "Tokens=2*" %%A In (
   'Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"'
  ) Do Call Set MBAMPATH=%%B

After running the script, he does a 'echo %mbampath$' which returns '%echopath%' Nothin' gets stored in the var and I'm at a complete loss because I don't have accesss to a 64-bit pc

%processor_architecture% is AMD64, not x64. The other thing is that your friend should be typing `echo %mbampath%`, rather than `echo %mbampath$`, but I guess that was just your typo!
snowcrash09
+5  A: 

There's no difference between batch files on x86 and x64 versions of Windows. The problem you have is due to WoW64 and transparent Registry redirection, see here for more details.

HKLM\SOFTWARE\Wow6432Node is the correct registry key for 32bit software on a 64bit installation of Windows, and this code works on my machine:

Set Reg.Key=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Malwarebytes' Anti-Malware
Set Reg.Val=InstallPath
For /F "Tokens=2*" %%A In (
    'Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"' )
Do Call Set MBAMPATH=%%B
echo %mbampath%

Your other post includes a conditional branch based on the %processor_architecture% environment variable. The problem with that is that (on my machine at least) %processor_architecture% is "AMD64" not "x64".

Why not just query both possible registry keys rather than branching based on architecture?

snowcrash09