title: Using Windows Command in .cmd to test if 32 bit or 64 bit and run a command
body: <p>I am writing a script that find a registry value and returns that value to the windows command prompt screen and also adds that to a .txt file. I am to a point where I need to also test to see if the machine is 32 bit or 64 bit so that I know which command to use to find the value I need in the registry. </p>
  
  <p>I am looking for logic along the lines of what I have written below:</p>
  
  <p>If 32 bit then (run this command)
  else
  (run this command)</p>
  
  <p>I am hoping to not have to have any text files or anything else required for this script to work. Below is the code I have so far. Due to the registry location being private, I changed the location to a made up location. (Note: I do have a text file this script reads from that I insert the names of computers and servers. So far the code I have works but with 2 registry find commands I am obviously not getting right results when its checking a 32 bit machine for a 64 bit registry location)</p>
  
  <pre><code>@echo off
  
  Setlocal
  
  ::sets the ldt variable to the local date and time in yyyymmdd_hhmmss
  for /f "skip=1" %%c in ('wmic os get LocalDateTime') do set ldt=%%c
  set ldt=%ldt:~0,8%_%ldt:~8,6%
  
  
  ::searches for computer names in servers.txt and then calls server sub routine. Once it goes back to the for loop it moves onto the next line in servers.txt
  for /f %%c in (servers.txt) do (
  set server=%%c
  call:server
  )
  pause
  goto:eof
  
  --------------------------------------------------------------------
  :server
  set stamp=%date% at %time%
  set DateTime=%stamp%
  
  ::Tests for a good ping, if no ping then move onto next machine
  ping -n 1 -w 250 %server% &gt; nul 
  if %errorlevel% NEQ 0 (
    ECHO No Ping on %server%
    ECHO No Ping on %server% &gt;&gt;AuditScript_%ldt%.txt
    goto:eof
  )
  call:screen
  call:log
  goto:eof
  
  --------------------------------------------------------------------
  :screen
  echo.
  echo Computer name: %server%
  reg query "\\%server%\HKLM\SOFTWARE\Registry Folder1\Information\" /V "Datavalue" | FIND "Datavalue"
  reg query "\\%server%\HKLM\SOFTWARE\Wow6432Node\Registry Folder1\Information" /V "Datavalue" | FIND "Datavalue"
  echo.
  goto:eof
  
  --------------------------------------------------------------------
  :log
  echo. &gt;&gt;AuditScript_%ldt%.txt
  echo Registry value for %server% on %stamp% &gt;&gt;AuditScript_%ldt%.txt
  reg query "\\%server%\HKLM\SOFTWARE\Registry Folder1\Information\" /V "Datavalue" | FIND "Datavalue" &gt;&gt;AuditScript_%ldt%.txt
  reg query "\\%server%\HKLM\SOFTWARE\Wow6432Node\Registry Folder1\Information" /V "Datavalue" | FIND "Datavalue" &gt;&gt;AuditScript_%ldt%.txt
  echo. &gt;&gt;AuditScript_%ldt%.txt
  goto:eof
  
  --------------------------------------------------------------------
  </code></pre>