C++程序看不到映射的驱动器
我正在使用 Visual Studio 2010 在 Windows 7 上编写非托管 C++ 控制台应用程序。我遇到了一个问题:本地计算机或网络位置上的文件工作正常,但我的代码看不到映射驱动器上的任何内容。我可以简单地将这个问题解决为以下两行的程序:
const WCHAR * libPath = _T("L:\MyFiles\myfile.txt"); DWORD fa = GetFileAttributes(libPath);
其中 fa 返回为 0xFFFFFFFF,L 是映射驱动器,L:\MyFiles\myfile.txt 是有效的文本文件。
如何访问映射驱动器?
I am coding an unmanaged C++ console application on Windows 7 using Visual Studio 2010. I ran into an issue where files on my local computer or a network location work fine, but my code can't see anything on a mapped drive. I can simply this issue to a program that is the following 2 lines:
const WCHAR * libPath = _T("L:\MyFiles\myfile.txt");
DWORD fa = GetFileAttributes(libPath);
Where fa comes back as 0xFFFFFFFF, L is a mapped drive, and L:\MyFiles\myfile.txt is a valid text file.
How do I access mapped drives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可能性是您的应用程序正在提升模式下运行(即选择
以管理员身份运行
)。 此处更详细地讨论了该问题。解决方案是使用
net use
挂载驱动器或将其合并到注册表中:请注意,进行上述更改后需要重新启动。
One possibility is that your application is running in elevated mode (ie. with
Run as administrator
selected). The problem is discussed in greater detail here.The solution is to use
net use
to mount the drive or merge this into your registry:Note that a reboot is required after making the above change.
这是 Visual Studio 的问题。 “启动而不调试”与从 Windows 7 上的资源管理器运行不同。该程序从 Windows 资源管理器启动运行良好。这是由于UAC权限不同造成的。
This is a problem with Visual Studio. "Start without debugging" is NOT the same as running from explorer on Windows 7. The program works fine started from Windows Explorer. This is due to different UAC rights.