0

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.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Cyprus106
  • 5,722
  • 6
  • 40
  • 48
  • 2
    This has already been [asked](http://stackoverflow.com/questions/2489613/how-to-get-system-folder-pathc-windows-c-program-files-in-windows-using-c). – Uli Gerhardt Mar 28 '11 at 15:45
  • Don't go surfing through the Registry for stuff like this. If it's not documented, then it may break in the future. Lots of paths in the Registry are there for backward compatibility with apps that didn't find the right API (SHGetSpecialFolderPath, SHGetFolderPath, SHGetKnownFolderPath, etc.). – Adrian McCarthy Mar 28 '11 at 17:49

5 Answers5

1

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

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

Community
  • 1
  • 1
abRao
  • 2,787
  • 1
  • 25
  • 37
  • It's typically "Program Files (X86)" that I need to get. I don't know if it's ever different on any other machine. Hence why I'd like to get it straight from Windows. – Cyprus106 Mar 28 '11 at 15:48
0

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.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
  • I've tried SHGetFolderPath, but when I #include Shlobj.h, it crashes HARD. FYI, I'm programming this on an XP machine, which could be the cause. Sadly, there's no way to NOT program it on an XP. Software issues. – Cyprus106 Mar 28 '11 at 19:03
  • I still use XP, and I've used this function many times. The crash is from something else. You can try `SHGetSpecialFolderPath` (http://msdn.microsoft.com/en-us/library/bb762204%28v=vs.85%29.aspx) which is a little simpler to call. – Adrian McCarthy Mar 28 '11 at 22:12
  • Are you using Borland or Visual? – Cyprus106 Mar 29 '11 at 14:54
0

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.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
-2

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.

broc
  • 222
  • 1
  • 2
  • mklink has the problem of being prohibited for a) normal users, and b) administrators if the group policy editor isn't used to specifically allow it to be used by an admin. This is *not* the thing asked for. – rubenvb Mar 28 '11 at 18:12