“The network name cannot be found” error while accessing SMB thru C#.

huangapple go评论63阅读模式
英文:

"The network name cannot be found" error while accessing SMB thru C#

问题

我正在以编程方式访问SMB网络共享驱动器,使用C#。

我看到了这个帖子如何在连接到网络共享时提供用户名和密码,它允许您定义UNC路径和一些凭据。

我已经使用类似的逻辑来提供访问共享的凭据,就像网络共享代码片段,但它们都显示错误67,该错误是“网络名称无法找到”。即使网络共享已映射为网络驱动器,错误仍然存在。

我现在遇到了困难,几乎所有我看到的帖子对我都不起作用。

这是我的代码,使用上面帖子中建议的类来访问网络共享。

NetworkCredential credentials = new NetworkCredential("user", "pass");
using (new smbconn(@"\2.168.1.89\Main-Storage\", credentials))
{
   Files = Directory.GetFiles(@"\2.168.1.89\Main-Storage\");
   MessageBox.Show(string.Join(Environment.NewLine, Files));
}

如果需要更多附加信息,请随时评论。谢谢

英文:

I am doing a programmatically access of a SMB Network Shared Drive using C#

I saw this thread How to provide user name and password when connecting to a network share which let's you define UNC path and some credentials.

I've used similar logic on giving the credentials on accessing the share like Network Share Gist but they both give an error 67 which is "The network name cannot be found". Even though the network share is mapped as network drive, the error still persists.

I am now hitting the wall to make work as almost all of the thread I've seen is not working for me.

This is my code accessing the network share using the class that is advised on the thread above.

NetworkCredential credentials = new NetworkCredential("user", "pass");
using (new smbconn(@"\\192.168.1.89\Main-Storage\", credentials))
{
   Files = Directory.GetFiles(@"\\192.168.1.89\Main-Storage\");
   MessageBox.Show(string.Join(Environment.NewLine, Files));
}

If more additional information is needed, please don't hesitate to comment. Thanks

答案1

得分: 0

I stumbled upon a really newer thread and has the same type of error with this.

Anders Finn Jørgensen Asnwer

It comes down on how the passed variables like the network path and credentials is being passed to the parameters of WNetAddConnection2.

It completely fixes the problem.

英文:

I stumbled upon a really newer thread and has the same type of error with this.

Anders Finn Jørgensen Asnwer

It comes down on how the passed variables like the network path and credentials is being passed to the parameters of WNetAddConnection2.

It completely fixes the problem.

huangapple
  • 本文由 发表于 2023年5月14日 22:23:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定