Using %PROGRAMFILES(x86)% on Windows OS 32bit - windows

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).

Related

Get the path to the 64-bit Program Files folder

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.

pnputil.exe is not recognized as an internal or external command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
When i executed the command via command propmt to install the driver :
cd C:\Windows\System32
pnputil.exe -i -a "C:\Users\Desktop\Drivers\IPEnabled_001.inf"
It work fine.
But if i execute the command in Installanywhere tool
It showing the error message:
pnputil.exe is not recognized as an internal or external command
So could you please tell why it is showing the error message and how the reslove that error?
Thanks in advance.
Please also suggest the alternate way to install inf driver
pnputil.exe is on 64-bit Windows available only as 64-bit application which means there is %SystemRoot%\System32\pnputil.exe (x64) but no %SystemRoot%\SysWOW64\pnputil.exe (x86).
Which directory becomes current directory on using cd C:\Windows\System32 depends on 64-bit Windows on architecture of the application which started Windows command interpreter cmd.exe. A 64-bit application starts really %SystemRoot%\System32\cmd.exe, but a 32-bit application starts %SystemRoot%\SysWOW64\cmd.exe. The reason is the Windows File System Redirector which redirects any file access to %SystemRoot%\System32 to the directory %SystemRoot%\SysWOW64 on Windows x64 for x86 applications.
It is best to check for existence of this file before executing it for this task running pnputil.exe existing only in directory %SystemRoot%\System32 on any Windows independent on Windows architecture.
if exist %SystemRoot%\System32\pnputil.exe (
set "SystemPath=%SystemRoot%\System32"
) else if exist %SystemRoot%\Sysnative\pnputil.exe (
set "SystemPath=%SystemRoot%\Sysnative"
) else (
echo ERROR: Cannot find pnputil.exe to install the driver.
echo/
pause
goto :EOF
)
%SystemPath%\pnputil.exe -i -a "%USERPROFILE%\Desktop\Drivers\IPEnabled_001.inf"
The first IF condition is true for 32-bit applications on 32-bit Windows and 64-bit applications on 64-bit Windows.
The second IF condition is true for 32-bit applications on 64-bit Windows. Sysnative is a special redirector for x86 applications on Windows x64. Sysnative does not exist for x64 applications. Sysnative is not a directory or a symbolic link or a hard link. So it is not possible to use if exist %SystemRoot%\Sysnative as this condition is never true. It is required to check if a file exists in the redirected directory, for example with if exist %SystemRoot%\Sysnative\* which is only true on running currently 32-bit cmd.exe on 64-bit Windows.
The final ELSE branch is true for example on Windows XP which does not have pnputil.exe at all.
However, it is not recommended to use pnputil.exe to install drivers. Microsoft publishes for free the Driver Package Installer DPInst. There is a 32-bit (dpinst32.exe) and a 64-bit version (dpinst64.exe). Installation of one or more drivers is very easy using the driver package installer.
Let us look on how hardware producing companies which offer also the appropriate drivers like Intel ® install drivers using Driver Package Installer.
There is usually a directory structure in a driver installer package like:
VISTA32
VISTA64
WIN7-x86
WIN7-x64
XPx86
XPx64
Or a directory structure like:
VISTA
x86
x64
WIN7
x86
x64
XP
x86
x64
The directory structure varies from installer package to installer package, but that does not really matter and usually it is quite easy to see which driver files in which directory are for which version of Windows including architecture.
And there are additionally dpinst32.exe and dpinst64.exe being either stored in parent directory of all the subdirectories with the driver files or on just two driver directories directly in the directory containing the driver files.
Let us make the driver installation example very simple and assume there are only two driver files in a package, one for Windows x86 and one for Windows x64.
WIN-32
dpinst32.exe
*.cat
*.dll
*.inf
*.sys
WIN-64
dpinst64.exe
*.cat
*.dll
*.inf
*.sys
The code to install the 32-bit driver(s) in WIN-32 on 32-bit Windows and 64-bit driver(s) in WIN-64 on 64-bit Windows by a simple batch file executed either by 32-bit or 64-bit cmd.exe is very easy.
set "WINARCH=64"
if "%ProgramFiles(x86)%" == "" set "WINARCH=32"
cd WIN-%WINARCH%
dpinst%WINARCH%.exe
The environment variable ProgramFiles(x86) exists only on Windows x64 which makes it very easy to determine the architecture of Windows, see also WOW64 Implementation Details. The architecture of the processor does not really matter because on a PC with an AMD 64-bit (compatible) processor can be installed nevertheless a 32-bit Windows.
dpinst32.exe and dpinst64.exe started without any option simply install all drivers found in current directory.

Tizen-sdk-for-wearable-setup Installation issue because of JAVA HOME

System Configuration:
OS - Windows 8
System type - 64-bit Operating System , x64-based processor
I have installed java-8 and set JAVA_HOME as
C:\Program Files\Java\jdk1.8.0
I am getting error as below image while Tizen-sdk-for-wearable-setup Installation.
error - Cannot execute Java even if it was installed. Check environment variable or Java version(over 1.6) please.
I tried installing after JDK 7 both 32 bit and 64 bit and setting JAVA_HOME - Program Files path and Program Files (x86) path both also it didn't worked.
I have a another system in which the Issue didn't occurred.
System Configuration :
OS - Windows 7 Enterprise
System Type - 32 bit operating system.
Installed Java - C:\Program Files\Java\jdk1.6.0_45
JAVA_HOME set as - C:\Progra~1\Java\jdk1.6.0_45
Now there may be many chances why installation is not getting in my win-8 64 bit.
64 bit JAVA support is not available.
I am not sure about ~ symbol in JAVA_HOME path but it may be to escape space between Program Files and I have not set java home using this symbol.
In win-8 64 bit I have 2 folders. Program Files and Program Files (x86) , I am not sure whether to use ~ or " " to set JAVA_HOME and for 32 bit java or 64 bit java installed.
May be only java 1.6 is supported right now.
I searched and found similar issues :
I find this link but not able to get why its advised to set the system environment Path Variable to 'c:\windows\system32'.
In this link its advised to use InstallManager.jar via cmd.exe.
I can try each possible assumption till it works but hoping to find a solution with proper reason why I am getting this error.
If any one knows how should I work this out please help.
At last solve the Issue.
Installed jdk1.7.0_51 (I think currently JAVA 8 is not supported).
Set the JAVA_HOME as C:\PROGRA~1\Java\jdk1.7.0_51 (thanks to #Michael comment).
This link: https://answers.madewithmarmalade.com/questions/16878/cant-install-tizen-sdk-on-windows-8-64-bit.html solved for me the problem of Tizen SDK installation:
Change directory to %LOCALAPPDATA%\Temp\tizensdk_TimeStampOfInstallationInvocation
java -jar InstallManager.jar
My system: Windows 7 Ultimate x64. Java's version installed (64 bit):
g:>echo %JAVA_HOME%
c:\Program Files\Java\jdk1.8.0_05
g:>echo %CLASSPATH%
c:\Program Files\Java\jdk1.8.0_05\jre\lib
Added to PATH: c:\Program Files\Java\jdk1.8.0_05\bin\
(Tizen IDE and "Hello World" example run just fine.)
I encountered the same problem and finally I realised that my version of Tizen installer is 64bit but I installed 32bit java in my computer. Then I downloaded 32bit Tizen installer and everything was fine.
I encountered the same problem, and it was solved by placing the Java path in the beginning of the system path ! weird.. but worked :)
You must include, depending on whether you downloaded the x86 or x64 Tizen installer, C:\Program Files (x86)\Java\jre7\bin or C:\Program Files\Java\jre7\bin in the PATH environment system variable. You can't use java 8. See this oracle page for instructions on setting environment variables. I have read some others mention that they put the entry at the very beginning of the PATH variable. I think this would only matter if you also had an entry for java 8, but better safe than sorry.

call 64-bit exe and 32-bit exe as a single file

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
)

Launching 64-bit executable from 32-bit Windows app

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.

Resources