I'm using this code to retrieve the volume serial
[DllImport("Kernel32.dll", SetLastError = true)]
extern static bool GetVolumeInformation(string vol, StringBuilder name, int nameSize, out uint serialNum, out uint maxNameLen, out uint flags, StringBuilder fileSysName, int fileSysNameSize);
public static uint GetVolumeSerial(string strDriveLetter)
{
uint serialNum, maxNameLen, flags;
bool ok = GetVolumeInformation(strDriveLetter, null, 0, out serialNum,out maxNameLen, out flags, null, 0);
return serialNum;
开发者_JS百科 }
It works great, except when I'm running as administrator through the application manifest UAC elevation it always returns 0 for mapped network drives (but it works otherwise)
Maybe the administrator user doesn't see the mapped drive for some reason (you'd think it was the other way around). Is there any way around this or simply invoking that code as the logged in user instead?
I'm on 64-bits Windows 7, but running the application in x86 mode
Mapped network drives are mapped for one user. When you connect as a different user, as far as that other user is concerned, the drive doesn't exist.
If you need several users to access the same network path, use the actual UNC path ("\\server\path
"). A mapped network drive is just a convenience for humans.
If you really need several users to access the mapped network drive, you'll need to map it for each user separately. You could, for example, do this in a batch file that runs on logon of each user and calls net use
(I'm not quite sure it would help with users such as SYSTEM, though).
精彩评论