资源管理器看不到WNetAddConnection2A映射的磁盘

来源:互联网 发布:岂取之易守之难乎翻译 编辑:程序博客网 时间:2024/05/18 18:44

   首先上一段C代码用于映射网络资源到本地,其实也就是net use做的工作:

#include <stdio.h>#include <windows.h>#include <Winnetwk.h>#pragma comment(lib, "mpr.lib")int wmain(int argc, wchar_t * argv[]){    NETRESOURCEA nr;    memset(&nr, 0, sizeof(NETRESOURCEA));    nr.dwType = RESOURCETYPE_DISK;    nr.lpLocalName = "W:";    nr.lpRemoteName = "\\\\192.168.1.30\\share";    DWORD dwRetVal = WNetAddConnection2A(&nr, "share", "share", 0);    if (dwRetVal == NO_ERROR)        printf("Connection added to %s\n", nr.lpRemoteName);    else        printf("WNetAddConnection2 failed with error: %u\n", dwRetVal);    return 0;}

  其实这真是特别easy的功能,但是我在资源管理器里面却看不到我所映射的磁盘!后来发现的原因是我使用了管理员权限运行了我的程序,参考StackOverflow提问:https://superuser.com/questions/1078117/why-isnt-file-explorer-showing-my-mapped-drives,同时也可以参考这篇文章:http://blog.csdn.net/russle/article/details/7402168

原创粉丝点击