Get program files directory from Windows in Borland C++ 6 - c++

I had to create an executable (using Borland C++ Builder 6) in place of a batch file for Windows 7, since permissions didn't allow ordinary users (non-admins) to run the necessary batch. We've got a number of different Windows 7 machines, some 64 bit and some 32, etc. The problem I'm running into is that the "Program Files" directory is hard coded in to the program, but it's not always the RIGHT program files directory, which leads to some errors on some machines.
I'm familiar the method for getting the program files dir from the registry, but I'm afraid this won't work on all machines because of permissions settings not allowing programs to access the registry. I've been searching high and low for a function like GetWindowsDirectory, but to no avail. Does ANYONE have any suggestions?
EDIT:
I've programmed this on a Windows XP Machine to simply be placed on Win7 (No way to change or avoid the XP/7 thing, crappy as that may be). It's a simple utility that needs no installation; it's just placed in a file. It just needs to go out and find the program files directory to perform some tasks.

This is first of all a deployment problem. You will have to copy/install your program to c:\program files (x86) on a 64-bit machine. You can simply use c:\program files in your code, Windows redirects it to the (x86) directory.
There is otherwise no easy cure for trying to bypass UAC. You'll have to embed a manifest in the executable to ask for admin privileges. The user gets the UAC prompt to let her know that you are going to be hacking the private parts. How to do this with such an old tool isn't obvious to me, you'll probably have to embed it in the .rc file. Or use a .manifest file.

How to get Program Files folder path (not Program Files (x86)) from 32bit WOW process?

Use SHGetFolderPath with CSIDL_PROGRAM_FILES.
There's a newer version called SHGetKnownFolderPath if you're always on Windows Vista or later, but you might need to update your Platform SDK. If you're still using Borland C++ 6, I suspect your Platform SDK might be older. In that case, you should be able to use SHGetFolderPath.

after installing the software, go to :
C:\Program Files\Borland\CBuilder6\Bin
Right click on bcb.exe file, choose
Properties -> Compatibility
Select the option - Run this program mode Windows XP(Service Pack 3) and Privilege Level
then, select the option Run as administrator, and then click Apply.
This works for my problem.

On windows 7 x64, just create a junction point in "c:\Program Files" pointing to the actual folder where the installation is in "c:\Program Files(x86)". This should be done by the same user who installs the software. That should not only take care of your problem but also third party packages that would not otherwise work on Win 7 x64.
If you don't know what a junction point is, just read the help for mklink.

Related

How does one deploy a VS, C++, OpenGL application to a second computer?

I am trying to simply deploy an OpenGL, C++ application from one computer to another. The app was written using Visual Studio 2017 Community. The first computer has VS installed, the second does not.
The computers have Intel Core i7-8550U CPU and Intel Atom x5-Z8350 CPU, respectively. Both are running Windows 10 Home.
The VS project started as an empty project to which I added everything.
I have copied the release, x64 application .exe file and the one .dll file necessary to the project development to a single directory on the second computer.
Microsoft instructions for local deployment say “Local deployment, in which you copy particular Visual C++ DLLs from your Visual Studio installation—typically in \Program Files (x86)\Microsoft Visual Studio version\VC\Redist\platform\library\—and install them on target computers in the same folder as the application executable. You can use this deployment method to enable installation by users who don't have administrator rights, or for applications that can be run from a network share.”
Nothing I can see or find to set in VS tells me what .dll files are being used by the application I developed and run on the first computer. There is a VS output window that shows a number of .dll files, but those are in c:\windows\system32.
From the reference in the Microsoft instructions regarding the MSVC DLLs in \Program Files (x86)\Microsoft Visual Studio version\VC\Redist\platform\library\, I looked in ..\VC\Redist\MSVC\14.16.27012\x64 on the first computer and found these folders:
I have copied the DLLs from the .CRT directory and the .MFC directory to the second computer to no avail.
When I try to run the application on the second computer it displays the message “Failed to create GLFW window”, which is in the code I wrote as shown here:
It would seem that there must be a straightforward way to do this. I have seen reference to an old Microsoft application (I think), depends.exe, which provides the a list of the DLLs required, but it is no longer deployed with Windows systems.
missing DLL or RTL
causes crash or even no error but just instant closing your app (that is what missing or miss-matching MSVCPP RTL is doing or was at some point).
As the RTL libs are changing all the time (IIRC once in a year) there are a lot of versions already so good luck using MSVCPP apps on fresh OS computers. In order to use some app you usually need to find out which version of RTL it needs which they usually do not report so you will end up with installing all of them you get hands on ...
There is a way around this problem just enable your compiler/linker to link all the stuff it needs directly into exe file instead of using RTL DLLs. However I do not code in MSVCPP and from what I heard MS removed this option from their environment (other compilers I use still have it)
Your error message indicates your App run as should and is not missing anything.
The problem is on GL side. Windows 10 is usually forcing wrong drivers (and not just for gfx cards). The goto case is enforcing (most likely intentionaly) buggy MS drivers (where GL is bugged and DX more or less works) instead of vendor provided. To remedy this (check the driver manufactor and if not what it should be) download&install correct driver from your gfx Vendor site Do not use Windows Driver service for gfx cards !!!
You can use DUMPBIN /DEPENDENTS EXENAME to get a list of bound DLLs. Mind you this only lists DLLs with import table entries, if you're instantiating COM objects this won't help at all.
My guess is you're probably missing the opengl driver/dll on the target system.
ed: actually I'm going to narrow that down to missing the driver, since if you were missing the DLL you'd have gotten an an error on load. The fact you're able to call the function means you bound to it, but that you're only getting failures when it tries to call the driver. Try calling something benign that queries for driver or device info, like a version or string. If that fails you know the driver is missing.

"Missing MSCVP140.dll" and "Missing VCRUNTIME140.dll" when running an .exe-File on another computer

I made a program in Microsoft Visual Studio C++ and used the SFML for this. I included the correct .dll-Files, that the program needed, and copied them into the "Release"-Folder. It worked. The entire program worked flawless on my computer, but as soon as I tried to run it on another computer, it said: Missing "MSVCP140.dll" and Missing "VCRUNTIME140.dll.
I searched for a solution of this program, and always heared "Go to Project > Project Settings > C/C++ > Code generation > Runtime libraries > switch to Multi-Threaded (/MT). I compiled the project with this settings, and the executable increased in size, which they said is normal, because there are no supporting .dll-Files anymore.
But as I tried it again, with the new .exe, it gave me the exact same Error-Messages. Are there any other possibilities to solve this WITHOUT installing some -dll-Files onto the computer?
This is covered on MSDN in some detail. See Deployment in Visual C++
You really have three choices:
Use the "centralized" versions of the DLLs. For this you should have a setup program that runs the VCREDIST_*.EXE packages for VS 2015 or if using a MSI-based setup you can use the MSM files provided.
Copy the required DLLs as part of your program. This means your installer or zip file or whatever that has the EXE includes the DLLs it needs too. This is the best choice if you want "copy and run" style deployment, but remember that all security servicing of the DLL is now your problem.
Use static linking. From a security perspective this is the least desired solution, and really should only be used in the specific cases of writing an installer--i.e. the program that installs an app has to run in the first place.
You have not specified which version of Windows is running on your target machine. VS 2015 does not support Windows 7 RTM as it's out of support, but it does support Windows 7 Service Pack 1 along with Windows Vista Service Pack 2, Windows 8.x, and Windows 10.
While we are on the subject note that Windows 8.0 is also out of support. Those users need to upgrade to Windows 8.1 Update or Windows 10.

C++ issues with Windows UAC

I have a software written in C++ installed in some 1000 PC which is having some difficulties with windows UAC. I'm trying to make things work properly but I would need some help to understand the problem and find correct solution.
Situation is as follows: I need to write some data in some text / xml files, so I started (in XP) to write them in the executable folder. Not recommended, I know. When Vista kicked in, all files started being saved to the VirtualStore folder, which was fine for me, so I left things untouched. I had some issues back then with a couple of users (see problem 1) but I fixed them by hand and that was it. Now with Windows 8 I'm facing different problems (problem 2) and I want to fix them properly once and for all.
First problem: with Windows Vista it happened that some users eventually found their software "empty", as it was when just installed. All their work on it was gone. It turned out that suddendly Vista was looking for their files in C:\Program Files\{MyApp} instead of looking in the VirtualStore. Copying the files from VirtualStore to Program folders solved the problem, never understood why
Second problem: now with Windows 8 some users [a minority of them] experience a different, strange fact; my app does not seem to be able to create files in the VirtualStore, but it can edit existing files. So if I create the files manually, everything works. If not the app does not work: files are not modified neither in the program folder nor in the virtual store
Now I want to fix up things. My plan is to move all the files that need modifications in CSIDL_LOCAL_APPDATA and to have the software save stuff there. Only executables will be in the program folder. For backward compatibility, though, it seems I cannot use SHGetKnownFolderPath which seem to be Vista+ specific. So I would use SHGetFolderPath, which is deprecated, I know, but should work in XP and act as a wrapper of SHGetKnownFolderPath in Vista+, which is good for me.
My questions:
any ideas about my problems 1 & 2? I'd like to understand them in order to be sure I defeated them complitely.
is my plan UAC compliant? As far as I understand it is, but...
any way to assure XP compatibility but for my workaround? I do not feel comfortable using deprecated functions, but I definitely do not want to have two versions (XP and Vista+) to deal with!
Thank you very much for any help you can provide.
Luca
These are my ideas to problems 1 & 2:
1. If you are writing the files your application is working with, your files will be written in a sub-directory of C:\Program Files. In order to write files at this location (C:\Program Files), your application must be run as Administrator. For compatibility reasons Windows Vista will write data to VirtualStore, if you try to write data to directories where you need Administrator rights to write data to.
2. Windows 8 does not use VirtualStore anymore. Read access does not require Administrator rights, however.
Yes, your plan is UAC compliant. Your program and the files your program uses must be saved in two different directories.
I would use the ShGetFolderPath function in order to get the path of the AppData directory. Additionally this function is compatible with Windows XP. You might check the operating system version and use the appropriate function/interface for this version. GetVersion and GetVersionEx have been changed in Windows 8. This is why I recommend the use of the Version Helper functions for version checking purposes on Windows 8.

Why is cudart32_50_35.dll not found?

I'm trying to start learning some basic CUDA and I've managed to get the application to compile, but when I debug it, it say's:
The program can't start because cudart32_50_35.dll is missing from your computer.
Every possible path to the file is located in the System Environment Variables, but it still manages to fail to locate it.
I'm using Windows 8 and Microsoft Visual C++ 2010 Express to code.
Any ideas?
You will want to make sure you have this in the path and make sure you restart visual studio when you make a change to the system path... it will still use the old path until you restart the program!
For Windows 7 the binary path for CUDA v5.0 is %CUDA_BIN_PATH%, or C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin. See if it is the same for you.
Alternately, as sgar91 points out, you can just copy all the .dll files in the above path to the same place you have the exe... but this is probably a bit much. In general, you should not have to run as administrator, and I have several programs running CUDA as a standard user.
I found out by myself. Be sue to always run application as administrators!

Application only runs if you run as administrator?

Edit: This problem only occurs on windows 7 and vista from what I've heard.
I have a very simple app developed with an external graphics library. If I install this app into a program files directory and run it, it will crash immediately but it works fine normally, with exactly the same files. I have realised it is because you need to run the application as administrator for it to work.
I appreciate if this is a problem directly related to the graphics engine I am using, but I don't really think so (but I'm clueless). Can anyone help me?
Edit for more detail:
The application executable and files that are needed to run it are installed into the default program directory - for me, C:\Program Files (x86). If you try and run with without clicking run as administrator, it will simple freeze and say "App has stopped working. Windows is checking for a solution to the problem..." My question is basically, how can I make it so run as administrator isn't necessary?
When a program cannot perform an operation, it (the operation) should fail gracefully. My guess is your application is attempting to do something that it cannot do as a normal user and then fails to check for a return code, and then subsequently crashes. You need to identify what it is your program is doing that it should not be able to do as a normal user. For example (off the top of my head):
Write a file to Program Files (x86)
Write to HKLM
(Without more details) The problem is most likely related to the fact that your program tries to write into the directory and then excepts the file creation/modification to actually have an effect. UAC prevents applications from writing the Program Files directories without administrator privilages. The solution is to redesign your application to not rely on such behavior or store the files in question in one of the intended locations (AppData, etc. folders).
If you right-click on the EXE and go to Properties -> Compatibility there are some options that might help. You could try running the app in compatibility mode for a previous Windows version or if that doesn't work at least mark the EXE to run as administrator by default.