Bladey001
asked on
Script help - msiexec based on 32/64 bit OS
Dear experts,
I need some help putting together a script that will check whether the client OS is 32-bit or 64-bit and depending on the result it will install an MSI package.
I had a quick search on the internet but a lot of the results come up with finding whether the processor architecture is 32 or 64 bit rather than whether the OS is.
So essentially what I need is something like:
If Package "Application X" is installed then go to end
If machine has 32-bit OS
Then msiexec \\Path\Packagex86.msi /q /norestart
If machine has 64-bit OS
Then msiexec \\Path\Packagex64.msi /q /norestart
I need some help putting together a script that will check whether the client OS is 32-bit or 64-bit and depending on the result it will install an MSI package.
I had a quick search on the internet but a lot of the results come up with finding whether the processor architecture is 32 or 64 bit rather than whether the OS is.
So essentially what I need is something like:
If Package "Application X" is installed then go to end
If machine has 32-bit OS
Then msiexec \\Path\Packagex86.msi /q /norestart
If machine has 64-bit OS
Then msiexec \\Path\Packagex64.msi /q /norestart
Don't do this by checking whether a directory exists, there are a host of reasons why the directory may exist when the OS is in fact running 32bit.
In windows NT the "%Processor_Architecture%" variable will return whether the environment is 32bit (x86) or 64bit (AMD64). This means the OS is running 32bit or 64 bit regardless of the actual hardware on the computer.
(Is. A 32bit OS installed on a machine with a brand new Intel i7 or AMD processor will return x86, even though the CPU is 64 bit)
Generally this is the most effective method to find the bit level as normally a batch file will run in the native bit level of the OS.
There is one caveat, and its quite unusual; if you run a 32bit application which calls the batch, depending on how it's called it may get it's local version of this variable set to x86 instead of AMD64. ( I have yet to experience this issue personally, but I've read about it before.)
To guard against this one issue that could occur to make the variable incorrect, you can query the registry to see what the OS is natively running as instead:
In windows NT the "%Processor_Architecture%"
(Is. A 32bit OS installed on a machine with a brand new Intel i7 or AMD processor will return x86, even though the CPU is 64 bit)
Generally this is the most effective method to find the bit level as normally a batch file will run in the native bit level of the OS.
There is one caveat, and its quite unusual; if you run a 32bit application which calls the batch, depending on how it's called it may get it's local version of this variable set to x86 instead of AMD64. ( I have yet to experience this issue personally, but I've read about it before.)
To guard against this one issue that could occur to make the variable incorrect, you can query the registry to see what the OS is natively running as instead:
reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE
@QCubed: Didn't know that variable existed - good to know. The rest of my code should still stand therefore to save to OP some effort:
IF %Processor_Architecture% == AMD64 GOTO Run64
msiexec \\Path\Packagex86.msi /q /norestart
GOTO End
:Run64
msiexec \\Path\Packagex64.msi /q /norestart
:End
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@JEaston, cool, always looking to help.
@OP: FYI, I'm writing on my android, so I have not yet tested the variable, please review for any spelling mistakes etc.
@OP: FYI, I'm writing on my android, so I have not yet tested the variable, please review for any spelling mistakes etc.
@JEaston, looking at your code, always wrap paths and variables used in compares within quotes, otherwise if they contain spaces they will cause syntax issues.
ASKER
Thanks guys
Is it possible to add the part near the beginning where if the application is already installed it ends the script? I suppose otherwise it will try and run the msi on startup each time
Is it possible to add the part near the beginning where if the application is already installed it ends the script? I suppose otherwise it will try and run the msi on startup each time
Open in new window
Also, to test for the program install you can add IF EXIST cases to test. You may need to do this within the 32-bit section and the 64-bit section as install locations may be different. For example add:
Open in new window