What is the "correct" way for a 32-bit application to find the "Program Files" folder on 64-bit Windows? For example, I am running a 32-bit application with a VBScript engine, and want to launch 64-bit Excel (using ShellExec, or similar). In the 32-bit world, I would check the environment variable "ProgramFiles" to get the base folder. My understanding is that as a 32-bit app on a 64-bit Windows, that environment variable will point to the 32-bit program files folder - eg: C:\Program Files(x86). But my 64-bit Excel will be under C:\Program Files.
I want to avoid hard-coding a reference to "c:\program files".
You can check the environment variable "ProgramW6432". It should exist and point to Program Files, without the x86, when running a 32bit application on a 64bit Windows.
Documentation: MSDN
Depending on the version of windows, you should be using the known folders apis.
http://msdn.microsoft.com/en-us/library/bb776911%28v=VS.85%29.aspx
Specifically you can use FOLDERID_ProgramFilesX64 in conjunction with SHGetKnownFolderPath.
Related
Which of these files( in setup folder), if execute can install a program on windows 7 ?
1- setup.com
2-setup.ini
3-setup.inf
COM files are executable in Windows. You should be able to run setup.com from the CMD prompt by cding to the directory setup.com is in, and running setup or setup.com.
Keep in mind, COM files cannot be executed on 64-bit versions of Windows, since these editions lack NTVDM, the MS-DOS-emulating subsystem that handles COM file execution. You would instead need to emulate the 32-bit environment using an emulator like DOSBox.
setup.inf can be used to file copy and installation. I cannot remember setup.com installers for Windows programs.
msdn inf description
I installed both VS2013 and VS2015 Professional (full install), and both have a "armasm.exe" under the bin folder. I set the bin folder into "path" environment variable. When I tried "armasm /?" under cmd, it prompts out a dialog box with a red cross sign, saying that:
The application was unable to start correctly (0x000007b). Click OK to close the application.
I wonder if this program is for ARM CPU's assembly language. Does this program only run on ARM machine that installed VS?
How can I get it to run?
I assume you're talking about the armasm.exe file in the \VC\bin\x86_arm folder? If so, then no, that is an x86 binary, not an ARM binary. It will run on your machine.
It is actually an ARM cross-assembler for x86. That means it allows you to assemble ARM binaries on an x86 host. Think of it like the x64 cross-compiler for x86 (in the x86_amd64) folder. That can compile 64-bit binaries on a 32-bit x86 host.
The reason you can't get it to start is because the environment has not been set up correctly, and required dependencies cannot be located. When I try to start it, I get a more descriptive message than you do:
System Error:
The program can't start because msvcdis140.dll is missing from your computer. Try reinstalling the program to fix this problem.
You are meant to use the vcvarsx86_arm.bat batch file (in the same folder) to get your environment set up correctly, before trying to run any of the tools. Step-by-step:
Open a new Command Prompt.
Drag in vcvarsx86_arm.bat, and press Enter to run it. This sets up your environment to run the x86/ARM tools.
Drag in armasm.exe (or simply type armasm.exe into the prompt, unqualified). It will now run because the environment has been correctly set up (including the path, so that it can be found without requiring the full path to be entered).
There is also a \VC\bin\amd64_arm folder. This contains tools for ARM executables that run on x64 hosts. You use those in exactly the same way, except you launch the vcvarsamd64_arm.bat file in that folder first.
It is worth noting that I also see a \VC\bin\arm folder, but (at least in my install of VS 2015) that contains only one EXE: pgosweep.exe. Microsoft does not appear to provide an ARM assembler that runs on ARM platforms. Which makes senseāI don't think ARM is a supported host for development. Visual Studio certainly hasn't been ported to ARM. Just use the ARM tools on x86 or x64.
I'm using Windows 7 (x64) and I require the path to my 64-bit Program Files folder.
To that end I tried using the ExpandEnvironmentStrings method, but but both examples below return the path the the 32-bit Progrom Files folder (C:\Program Files (x86)).
pfPath = Shell.ExpandEnvironmentStrings("%PROGRAMFILES%")
pfPath = Shell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")
I've also tried reading the registry value of ProgramFilesDir, but that returns the path of the 32-bit folder as well, despite the key actually containing the correct path (I've checked the registry).
pfPath = Shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir")
Is there another way of doing this that may yeild the correct path?
Your program is running on WOW64. Use the ProgramW6432 environment variable to get the real x64 program files path when your program is running 32-bit.
Note that this environment variable only exists when the program is executing under WOW64. If you expect your program to also run on x86 Windows, you need to use the plain PROGRAMFILES environment variable.
So, try ProgramW6432, else fall back to PROGRAMFILES. There may be a more practical way to determine if the OS is x64 or not with VBScript that you can also use.
What happens when I use the environment variable %PROGRAMFILES(x86)% on a Windows OS that is 32bit (ie, older versions of Windows such as Windows XP, Vista)?
I am hoping that it will simply resolve to: C:/Program Files. Will this occur?
According to this the environment variable %PROGRAMFILES(x86)% is only available on 64-bit systems.
However, if you are on a 64-bit system and use %PROGRAMFILES%, the result you get depend on whether the process requesting the environment variable is 32-bit or 64-bit.
So from a 64-bit process on a 64-bit system you would get C:\Program Files, from a 32-bit process on a 64-bit system you would get C:\Program Files (x86), and from a 32-bit process on a 32-bit system you would get C:\Program Files.
If this doesn't help, perhaps you can comment or edit your original question to make it specific what you are trying to do. As it currently stands, the answer to your question is "No".
Keith Hill answered this question here, summary:
${env:ProgramFiles(x86)} is not defined on a 32-bit machine
If you always want to put/get data to/from x86 directory, then you can use this code to determine file paths:
$file = "\file"
if ("${Env:ProgramFiles(x86)}")
{
$fullPath = "${Env:ProgramFiles(x86)}\$file"
}
else
{
$fullPath = "${Env:ProgramFiles}\$file"
}
Since %ProgramFiles(x86)% is not defined on Windows 7 32 bit, here is a workaround I came up with:
SET MyPath="%ProgramFiles(x86)%\MyFolder\MyApplication.exe"
rem workaround for Windows7 32 bit:
IF NOT DEFINED ProgramFiles(x86) SET MyPath="%PROGRAMFILES%\MyFolder\MyApplication.exe"
Use case: I want to call an application from a batch file that is installed:
on Windows 7 32 bit in C:\Program Files\MyFolder\MyApplication.exe
on Windows 7 64 bit in C:\Program Files(x86)\MyFolder\MyApplication.exe
This way %MyPath% always points to the correct path.
If you use %programfiles% on a 32-bit computer/laptop it will open C:\Program Files.
If you use %programfiles% on a 64-bit computer/laptop it will open C:\Program Files.
If you have a 64-bit program installed on a 32-bit computer/laptop, it will be installed in a new folder named Program Files (x64), which is located in the "C" drive. In which case you have to use %programfiles(x64).
If you have a 32-bit program installed on a 64-bit computer/laptop, it will be installed in a new folder named Program Files (x86), which is located in the "C" drive. In which case you have to use %programfiles(x86).
How can I call a 64-bit exe from a 32-bit exe in windows 7?
My requirement is I have created a batch file and have converted into exe using iexpress.
This exe works fine when I converted this exe from a 32-bit pc for a 32-bit pc.
And This exe works fine when I converted this exe from a 64-bit pc for a 64-bit pc.
When I tried to run 64bit from 31bit pc it show error Not valid
But I need to include this both for a single installation and call.
How can I do this ?
Excuse me, I think there is a misunderstanding here.
I understand that you have both .exe versions of a same program, one for 32-bit and one for 64-bit. However, you want NOT to execute both versions in every computer, but just the appropriate version for the underlaying OS, isn't it?
This way, you must include both .exe files in the installation files, but copy just one in the computer, so you just need to identify the version of the installing computer:
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
rem The OS is 64 bit
copy D:\program_v64.exe C:\program.exe
) else (
rem The OS is 32 bit
copy D:\program_v32.exe C:\program.exe
)