5

Given that I am executing an EXE file (D2006 app) on a machine across the network, how can I get the pathname to the commondocs folder on that machine, given that the EXE might have been invoked from a UNC shortcut or a mapped drive letter shortcut, and the platform of the remote machine is not necessarily known (but will be >= WinXP)?

The situation is where the client has a large number of dispersed machines, and they can't be bothered installing my app on all the PC's. So what they do is install the executable somewhere on the network and give everybody a shortcut to that. This already seems to suit them fine and there are no issues there.

At their request, I made the app read the settings from an INI file placed in the same folder as the executable. I can only assume they have configured things so that all the users can write to that folder so that the INI file can be saved back.

However, I want to change it so that the INI file is read and saved to somewhere in the commondocs folder tree on the remote machine, so that they don't need to provide write access to a Program files folder.

rossmcm
  • 5,493
  • 10
  • 55
  • 118
  • 1
    I doubt you can, because I think you need to be logged into the machine to get this information. – Misha May 20 '11 at 02:51
  • Hi @Misha. More detail added to question - thanks R – rossmcm May 20 '11 at 03:24
  • "The situation is where the client has a large number of dispersed machines, and they can't be bothered installing my app on all the PC's". If they can manage them, they can also manage software of them. If they are unable to manage them, well, they have a problem... ;) –  May 20 '11 at 10:56

1 Answers1

10

The machine that's running your program is the only machine you have access to. The machine where your program is stored is irrelevant. It's just a disk drive. It might not be running Windows. It might even be a NAS that's hardly running anything at all.

If the customer wants the common-documents folder of the file server to act as the common-documents folder for everyone on all the client systems, then get the sysadmin to configure a shared folder on the server and then configure the clients to use that remote folder as their common-documents folder. There is no special programming required on your part for that.

To get the common-documents folder of the machine your program is running on, you can call any of various API functions, including ShGetFolderPath. The CSIDL value you need is CSIDL_COMMON_DOCUMENTS. If you call SHGetKnownFolderPath instead, use FOLDERID_PublicDocuments.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Thanks @Rob. The thing is, the client doesn't want to have anything to do with the workstations. All he wants to do is install the app on the server. If the installation of the app created `{pf}\MyApp` for the executable and `{pf}\MyApp\Application Data` for the INI file (and gave the `{pf}\MyApp\Application Data` folder "everyone-modify" access), wouldn't that work? I could work out where the INI file was from the path to the executable, everyone would have read-write access to the INI file folder, and nobody could modify any other `{pf}` folder. – rossmcm May 20 '11 at 09:48
  • Yes, that sounds like a fine alternative. Good idea. – Rob Kennedy May 20 '11 at 13:07