I am working on an application that needs to correctly detect all used drive letters on Windows. And I use the GetLogicalDrives()
function for that. This function works just fine excepts when users launch my application with elevated privileges (i.e., the user logged in with an account belongs to 'Administrators' group and launch my application by choosing "Run as administrator" option). In this case, GetLogicalDrives()
fails to detect mapped network drives on the machine.
It seems that the root cause of the problem is that in this scenario Windows runs 2 user sessions in parallel. My application runs in the "elevated privileges" session, while the drive is mapped in the "non-elevated" session:
Is there any programmatic workaround for this problem? I tried to relaunch my application in the "non-elevated" session, but don't know how (or if it is even possible). What I tried already is relaunching my application with a restricted token (using CreateRestrictedToken
with DISABLE_MAX_PRIVILEGE
option), hoping that Windows will somehow figure out that it could now relaunch my application in a "non-elevated" session, but it did not work.