Jump to content

Batch file to run corresponding bitness commands, 32 bit or 64 bit


NaJeEb303

Recommended Posts

hello everyone,

i need some help in a batch script, a very common problem, surfed the internet alot and als0 found many answers but stil didnt get what i'm looking for,


so, i have two installers for a program , 32 bit.exe and 64 bit.exe, i want to install the program via batch script to the corresponding OS bit, a batch script that detects if the current windows is 32 bit, then installs the 32 bit setup and vice versa, also i want a flexible script, like if i have a crack for that program and also i want to copy the crack to the program directory after the installed program, so the script must contain a labelled " :x86 " and " :x64 " sections, and after the bit detection the appropriate commands from the corresponding sections should run..


here's a sample script;




@ECHO OFF

IF EXIST "%programfiles(x86)%" (GOTO 64-Bit) ELSE (GOTO 32-Bit)

:32-Bit
run 32 bit commands
GOTO END

:64-Bit
run 64 bit commands
GOTO END

:END



but i dont want the end command in the script, because i may add more commands in the same script....!


hope you got my point , BATCH Guys :D , help me...!!! :rolleyes:

Link to comment
Share on other sites


  • Replies 8
  • Views 2.3k
  • Created
  • Last Reply

Top Posters In This Topic

  • NaJeEb303

    4

  • CODYQX4

    2

  • Dodel

    1

  • ExXxtreme

    1

Top Posters In This Topic

Hello,

firstly, you could improve your script with the architecture check, see my script:

@ECHO OFFIF %PROCESSOR_ARCHITECTURE%==x86 GOTO 32-Bit) ELSE (GOTO 64-Bit) :32-Bitrun 32 bit commands....run whatever...GOTO END :64-Bitrun 64 bit commands....run whatever...GOTO END :END

And secondly, what do you mean with running more commands in same script? I wrote the script as I understood your question...

greetZ

ExXxtreme

Edited by ExXxtreme
Link to comment
Share on other sites


END is required in the script to stop it executing further commands or simply running in a loop constantly. What ExXxtreme has posted is exactly what you need, then all you need to do is fill in the 32 / 64 bit specific commands.

ExXxtreme's code :-

@ECHO OFF
IF
%PROCESSOR_ARCHITECTURE%==x86 GOTO 32-Bit <-- detect OS version and jump to 32bit or jump to 64bit if it's 64bit)
) ELSE (
GOTO 64-Bit
)

:32-Bit
run 32 bit commands

run whatever...
GOTO END <-- jump to end after executing 32 bit commands. (if this wasn't here it would try to then execute the 64bit commands also)

:64-Bit
run 64 bit commands

run whatever...
GOTO END

:END <- Exit script after running either 32bit of 64bit commands as per above,

Edited by Dodel
Link to comment
Share on other sites


if exist %windir%\syswow64 (

start /wait programX64 /s

) else (

start /wait programX86 /s

)

copy /y key for youre program "programs directory"

exit


a sample how it could be done.


first it looks for architecture (X64 - X86) then when found it starts the corresponded (program)

then it could copy the key or regfile in to that folder !



i hope it helps (working here with winrar)
Link to comment
Share on other sites


Sorry guys for being too late,

Hello,

firstly, you could improve your script with the architecture check, see my script:

@ECHO OFFIF %PROCESSOR_ARCHITECTURE%==x86 GOTO 32-Bit) ELSE (GOTO 64-Bit) :32-Bitrun 32 bit commands....run whatever...GOTO END :64-Bitrun 64 bit commands....run whatever...GOTO END :END

And secondly, what do you mean with running more commands in same script? I wrote the script as I understood your question...

greetZ

ExXxtreme

Thanks ExXxtreme, your code is working for me, :showoff:

END is required in the script to stop it executing further commands or simply running in a loop constantly. What ExXxtreme has posted is exactly what you need, then all you need to do is fill in the 32 / 64 bit specific commands.

ExXxtreme's code :-

@ECHO OFF
IF %PROCESSOR_ARCHITECTURE%==x86 GOTO 32-Bit <-- detect OS version and jump to 32bit or jump to 64bit if it's 64bit)
) ELSE (
GOTO 64-Bit
)

:32-Bit
run 32 bit commands

run whatever...
GOTO END <-- jump to end after executing 32 bit commands. (if this wasn't here it would try to then execute the 64bit commands also)

:64-Bit
run 64 bit commands

run whatever...
GOTO END

:END <- Exit script after running either 32bit of 64bit commands as per above,

Thanx for the explanation , it w0rked ... :rolleyes:

Link to comment
Share on other sites


Hello,

firstly, you could improve your script with the architecture check, see my script:

@ECHO OFFIF %PROCESSOR_ARCHITECTURE%==x86 GOTO 32-Bit) ELSE (GOTO 64-Bit) :32-Bitrun 32 bit commands....run whatever...GOTO END :64-Bitrun 64 bit commands....run whatever...GOTO END :END
And secondly, what do you mean with running more commands in same script? I wrote the script as I understood your question...

greetZ

ExXxtreme

NOTE: If this gets run under WOW64 (a SFX likely will do this), the batch will be lied to and told the architecture=x86 hence causing it to treat the whole OS as 32 Bit.

A common way floating around MDL is the following:

@echo offsetlocal EnableExtensionssetlocal EnableDelayedExpansionreg.exe query "hklm\software\microsoft\Windows NT\currentversion" /v buildlabex | find /i "amd64" >nul 2>&1if %errorlevel% equ 0 set xOS=x64if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if not defined PROCESSOR_ARCHITEW6432 set xOS=x86 if "%xOS%"=="x86" (echo "I AM 32 Bit OS") ELSE (echo "I AM 64 Bit OS")

Note the PROCESSOR_ARCHITEW6432 check. If it is defined you know it (WOW64) is lying to you and you are really an x64 OS.

You still if running under WOW64 may have issues with some commands, especially registry access, because of the redirection. This plagued the batch Office Toolkit V1.X with issues in this case and it was difficult to work around.

thanx cody, but this script only shows me the Bitness of my OS, i.e 32 bit or 64 bit, can you edit the script for me so i can put my 32 bit and 64 bit commands in it, as provided by @ExXxtreme .... thanx ;)

Edited by NaJeEb303
Link to comment
Share on other sites


thanx cody, but this script only shows me the Bitness of my OS, i.e 32 bit or 64 bit, can you edit the script for me so i can put my 32 bit and 64 bit commands in it, as provided by @ExXxtreme .... thanx ;)

You want the GOTO? Usually I just embed my stuff inside the parenthesis and then I don't need an :END.

@echo offsetlocal EnableExtensionssetlocal EnableDelayedExpansionreg.exe query "hklm\software\microsoft\Windows NT\currentversion" /v buildlabex | find /i "amd64" >nul 2>&1if %errorlevel% equ 0 set xOS=x64if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if not defined PROCESSOR_ARCHITEW6432 set xOS=x86 if "%xOS%"=="x86" (x86 Command 1...x86 Command 100) ELSE (x64 Command 1...x64 Command 100)

Thank you s0 much man.., now i g0t what i wanted..., u r0ck.. thnx agn..! :showoff: :rolleyes:

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...