开发者

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

开发者 https://www.devze.com 2023-02-20 12:42 出处:网络
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

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 开发者_如何学JAVAregistry, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消