如何以编程方式访问文件共享 [英] How do I access a file share programmatically
问题描述
我有一个不在域中的计算机上运行的Windows窗体应用程序,该应用程序需要能够将文件从本地文件系统移至UNC路径。我有该路径的用户名和密码。我想知道有没有办法直接执行 net.exe
命令来执行此操作?
I have a windows forms app running on a machine that is not on a domain, that needs to be able to move a file from the local filesystem to a UNC path. I have a username and password for that path. I was wondering is there any way to do this directly with out execing the net.exe
command?
理想情况下,我不必映射驱动器。
Ideally I wouldn't have to map a drive.
推荐答案
此问题的可接受答案此处似乎值得研究;它建议使用Win32 API函数 WNetUseConnection 。
The accepted answer on this question here seems like it would be worth looking into; it suggests using the Win32 API function WNetUseConnection.
从MSDN:
WNetUseConnection 函数与网络资源建立
连接。
函数可以将本地设备
重定向到网络资源。
The WNetUseConnection function makes a connection to a network resource. The function can redirect a local device to a network resource.
这似乎可以完成您的任务重新查找,而没有提及 net.exe
。这有帮助吗?
Which seems to accomplish what you're looking for, with no mention of net.exe
. Does this help?
这篇关于如何以编程方式访问文件共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!