阅读:3136回复:6
如何获得网络驱动器的真实路径?
假设我把\\192.168.100.10\D:影射为Z:盘,那么我在驱动中如何获得Z:的真实路径,即如何获得\\192.168.100.10\D:?请高人指点一下。
|
|
沙发#
发布于:2010-04-18 14:56
请知道的说说呀,困惑好久了
|
|
板凳#
发布于:2010-04-19 13:56
难道这个问题很难,没有人知道吗?
|
|
地板#
发布于:2010-04-19 23:14
You can easily get this information by calling Win32 API WNetGetConnection() in user mode.
You can query corresponding registry keys as well. But bear in mind, mapped drive is basically a user-mode concept. It's per-logon-session based. |
|
地下室#
发布于:2010-04-21 09:10
谢谢michaelgz的指点,我试试从应用层取一下。
|
|
5楼#
发布于:2010-04-23 09:17
我写了一个方法,不知是否满足楼主的需要
//将Unicode指针变量转换为Char数组 BOOLEAN UnicodeStringToChar(PUNICODE_STRING UniName, CHAR Name[]) { ANSI_STRING AnsiName; NTSTATUS ntstatus; CHAR* nameptr; __try { ntstatus = RtlUnicodeStringToAnsiString(&AnsiName, UniName, TRUE); if (AnsiName.Length < 260) { nameptr = (PCHAR)AnsiName.Buffer; //Convert into upper case and copy to buffer strcpy(Name, _strupr(nameptr)); //KdPrint(("UnicodeStringToChar : %s\n", Name)); } RtlFreeAnsiString(&AnsiName); } __except(EXCEPTION_EXECUTE_HANDLER) { KdPrint(("NPUnicodeStringToChar EXCEPTION_EXECUTE_HANDLER\n")); return FALSE; } return TRUE; } BOOLEAN GetFileDosName(PFLT_FILE_NAME_INFORMATION nameInfo, PCFLT_RELATED_OBJECTS FltObjects, CHAR Name[]) { CHAR FileName[260] = "X:"; CHAR VolumeName[260] = "X:"; CHAR DeviceName[260] = "X:"; int iLen; NTSTATUS status; UNICODE_STRING dName; PAGED_CODE(); RtlZeroMemory(FileName, 260); if (!UnicodeStringToChar(&nameInfo->Name, FileName)) { return FALSE; } //判断是否要忽略的文件,如果文件名内有:说明是要忽略的,另网络映像也会有冒号 /*RtlZeroMemory(VolumeName, 260); UnicodeStringToChar(&nameInfo->Volume, VolumeName); iLen = strlen(VolumeName); if (strstr(FileName, ":") != NULL) { if (strstr(VolumeName, ":") == NULL ) { return FALSE; } }*/ if (nameInfo->Share.Length> 0) { //共享目录 //将VolumeName替换为\ RtlZeroMemory(Name, 260); *Name =92; RtlCopyMemory(Name+1, FileName+iLen, strlen(FileName) - iLen+1); //KdPrint(("FN-sg2:%s\n",Name)); } else { //本地目录 RtlZeroMemory(Name, 260); status = IoVolumeDeviceToDosName(FltObjects->FileObject->DeviceObject, &dName); if (NT_SUCCESS(status)) { RtlZeroMemory(DeviceName, 260); UnicodeStringToChar(&dName, DeviceName); //得到盘符C: RtlCopyMemory(Name, DeviceName, 2); RtlFreeUnicodeString(&dName); } //将VolumeName替换为C: RtlCopyMemory(&Name[2], &FileName[iLen], strlen(FileName) - iLen+1); } //KdPrint(("DosFN-%s\n",Name)); return TRUE; } |
|
6楼#
发布于:2010-04-27 22:41
谢谢ander5115!我正在试着从应用层取,等这个有结果了试试你的方法,谢谢了!
|
|