How can I resolve a ERROR_BAD_NET_NAME error in a call to WNetAddConnection2?

后端 未结 1 926
慢半拍i
慢半拍i 2021-01-27 00:40

I am still trying to resolve a problem I\'m having, the first part of it was that I apparently need to call WNetAddConnection2 in order to use CreateFile to open a file across a

相关标签:
1条回答
  • 2021-01-27 01:10

    You are right about why it's not working. You are passing a local file name (e.g. Z:\Documents\somefile.txt) when you should be passing a share name (e.g. \\myserver\sharename).

    If the share is already connected to Z: then you don't need to call WNetAddConnection2.

    If the share is not already connected to Z: then there's no way you can automatically convert Z:\Documents\somefile.txt to a remote name because Windows has no idea what Z: represents.

    If the share might not be connected then your program needs to know in advance what share Z: is supposed to connect to and make the connection itself. You can either connect the share to Z: and use the existing path, or connect it with no drive letter and adjust the path yourself; you just need to replace the Z:\ with \\myserver\sharename\.

    0 讨论(0)
提交回复
热议问题