Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Windows Command in .cmd to test if 32 bit or 64 bit and run a command

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.

I am looking for logic along the lines of what I have written below:

If 32 bit then (run this command) else (run this command)

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)

@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% > nul 
if %errorlevel% NEQ 0 (
  ECHO No Ping on %server%
  ECHO No Ping on %server% >>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. >>AuditScript_%ldt%.txt
echo Registry value for %server% on %stamp% >>AuditScript_%ldt%.txt
reg query "\\%server%\HKLM\SOFTWARE\Registry Folder1\Information\" /V "Datavalue" | FIND "Datavalue" >>AuditScript_%ldt%.txt
reg query "\\%server%\HKLM\SOFTWARE\Wow6432Node\Registry Folder1\Information" /V "Datavalue" | FIND "Datavalue" >>AuditScript_%ldt%.txt
echo. >>AuditScript_%ldt%.txt
goto:eof

--------------------------------------------------------------------
like image 744
Patrick Avatar asked Nov 22 '25 03:11

Patrick


1 Answers

FOR /F "tokens=3" %%x in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V PROCESSOR_ARCHITECTURE') do set CPU=%%x
echo CPU Architecture: %CPU%
if "%CPU:~-2%"=="64" (
  echo Do This
) else (
  echo Do That
)
like image 197
James K Avatar answered Nov 24 '25 22:11

James K