views:

568

answers:

1

We have an application that needs to know the path that it is executed from (which is always a network path).

We set up part of our configuration based on the path that the application is launched from, and we really want that configuration to use mapped network drive paths instead of the UNC path to the resource.

What we've found is that when we launch our application without UAC elevation, we are able to get the directory that the application launched from using

GetModuleFileName(NULL, buf, sizeof(buf));

But when we launch elevated (which we actually need to do), the buffer returned gives us a UNC based path instead of a drive letter based path.

Note that we always launch from Windows Explorer by navigating into the folder tree of the mapped drive letter.

Does anyone have any suggestions on how to get the drive letter based path of the EXE from a process that is running elevated?

+2  A: 

Mapped Network Drives with UAC

Andrew Coleson
Great resource - thanks. Now is there anything we can do about it?
Kevin Day
Looks like you can't do anything about it - which makes sense: not everyone is going to have a mapped drive. Using UNC paths is the preferred way of dealing with network resources. Is there a burning reason why you don't want to use a UNC path?
Ian Boyd
Better late than never - the reason we don't want to use UNC paths is they void an important level of indirection. If all of our config files are hard coded to UNC paths, and a server name changes (or the server itself changes to a different server), we are dead. If we use mapped drives, then the name change is as simple as adjusting a login script.
Kevin Day
Windows DFS allows for a similar redirection. You can have \\mydomain.com\FOO point to \\someserver\someshare
Christopher Painter