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.
Related
I'm manually parsing the PEB's of a WOW64 process to get the modules loaded in it and was wondering why the file path (FullDllName) points to the x64 version of the module.
For instance, ntdll.dll's file path (taken from the WOW64 PEB) points to the DLL in the System folder which would be the x64 ntdll.dll, however, I would expect the file path to point to the x86 ntdll.dll in the SysWOW64 folder?
Why is this happening?
In the x64 system, some special directories and special registry keys are divided into two separate parts. For file systems, the %systemroot%\system32 directory is reserved for 64-bit files, and 32-bit files are redirected to the %systemroot%\SysWOW64 directory. In other words, all 32-bit programs will normally only appear in the %systemroot%\SysWOW64 directory. Any 32-bit program attempting to access the %systemroot%\system32 directory will be redirected to the %systemroot%\SysWOW64 directory. This is a default behavior unless the thread of the program explicitly specifies that the redirection mechanism needs to be turned off.
Sometimes you need to close redirection when you need to access the system 32 folder, so MSDN has provided a set of functions to control redirection:
Wow64EnableWow64FsRedirection
Wow64DisableWow64FsRedirection
Wow64RevertWow64FsRedirection
MSDN provides DEMO, which you can refer to
Where is wscript.exe located in Windows? Is is possible to locate the path by the help of Windows Registry?
I need this for my application and it would be great to have a common solution that would give correct location for ranging between XP to Windows 10.
It's in the system32 directory (+syswow64 for the 32bit exe)
You can verify this at the command line with where wscript.
Since its in the PATH environment variable you should never really need to know its path: it can be called from anywhere.
I'm building a program Using Qt Creator 5.2.1 (32 bit) with Mingw. One of the dependencies of this program is the libcurl library.
QT was building the file properly, however, when running, it would throw an error 139.
After running the dependency walker on the binary, I noticed that the libcurl dll in turn depends upon another dll called "libeay32.dll".
I did the following:
Copied the my program along with all required libraries(including
libeay32.dll) externally to Qt and ran it (this was successful).
After that I tried running from within QT, but having the libeay32 library in the build before running (this was successful)
Logically, I presumed afterward, that if I put the path to the libeay32 prior to any other paths within my PATH variable, that It would pull the correct version of the lib (re: answer to question here). However this did not work, throwing the same error 139 (it's apparently not finding the library)
I know I could run and test my program by simply copying the file into my working directory, however, for information purposes, I was wondering;
Is there any way of doing this without having to copy this DLL?
My instinct would have been that fixing the Path to point to this firstly would have helped as this would ensure that the DLL is pulled used before any other occurrences that may be there in other dirs.
Note: In referring to the PATH variable, I mean both the SYSTEM path and checking for the PATH Qt uses (Qt adds a few dirs to the path)
Thanks in advance for any help.
Either you link static, or you have to ensure that your library is located in one of the following locations (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#standard_search_order_for_desktop_applications):
The directory from which the application loaded.
The current directory.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.
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).
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.