We are using impersonation by using the LogonUser
function from advapi32.dll
along with the WindowsIdentity
class to perform impersonation.
In the application I want开发者_运维技巧 to show all drives that the user normally can see in the windows explorer. Therfore I use the DriveInfo.GetDrives()
method. But I only get the local drives, not the drives that were mapped from the network.
How can I achieve this?
Thanks, Florian
If you're impersonating the user correctly, then you have access to their network resources. e.g., using UNC paths should work as expected.
I believe there isn't a supported solution, but you could trudge through the registry for network drive mappings (HKCU\Network) and look up their UNC paths manually.
I just ran into this issue - it appears the mapped drives are not available to the impersonated account. We ended up converting the mapped drive path to UNC paths using the currently logged in account, then passing those files into the impersonator to do the actual work.
This answer was helpful for converting file paths from mapped drive to UNC: https://stackoverflow.com/a/19120925/892536
精彩评论