如何访问文件共享programattically [英] How do I access a file share programattically

查看:171
本文介绍了如何访问文件共享programattically的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体的机器是不是在一个域,需要能够从本地文件系统将文件移动到一个UNC路径上的应用程序运行。我有一个用户名和密码,这条道路。我想知道有没有什么办法可以直接与出execing的 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.

推荐答案

在这个问题上<一个接受的答案href="http://stackoverflow.com/questions/659013/accessing-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials/684040#684040">here看起来这将是值得期待;它建议使用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?

这篇关于如何访问文件共享programattically的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆