Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7644457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:41:36+00:00 2026-05-31T09:41:36+00:00

I am still trying to resolve a problem I’m having, the first part of

  • 0

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 network share.

Having done so, I am now receiving an ERROR_BAD_NET_NAME return from the WNet…2 call.

The remote resource is a mapped network folder on a windows network (the client, where we are, is windows xp). The network resource should be connected on startup, but it’d probably be bad to assume that, of course. The folder maps to local Z:. I am able to access, read, write and delete files from the destination folder on the machine using Explorer.

HANDLE initFile ( LPCTSTR iNCfileName ) {
    DWORD dw;
    HANDLE fHandle=NULL;

    NETRESOURCE nr = {0}; //new structure for network resource
    nr.dwType = RESOURCETYPE_ANY; //generic resource (any type allowed)
    nr.lpLocalName = NULL; //does not use a device
    // typical iNCfileName is std::string a="Z:\\Documents\\somefile.txt".c_str()
    nr.lpRemoteName = (char*)iNCfileName;
    //"\\\\DOMAIN\\PATH\\FOLDER"; 
    nr.lpProvider = NULL; //no provider

    // CONNECT_CURRENT_MEDIA ??
    DWORD ret = WNetAddConnection2 (&nr, NULL, NULL, CONNECT_TEMPORARY); 

    //...

    return fHandle;
}

I think that the problem is I cannot use Z:\Documents\somefile.txt but rather should be using the \\DOMAIN\PATH\FOLDER notation. If that’s the case, how do I programatically obtain that information so that I can provide it as input? Did I misunderstand the orignal answerer that I can convert the file name to \\\\Z\\Documents\\somefile.txt? If so is there a resource to perform this or should I parse the string myself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:41:37+00:00Added an answer on May 31, 2026 at 9:41 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use this solution but Eclipse still cant resolve Attachment and DataService.
still trying to find where i would use the yield keyword in a real
I'm still trying to decide whether my (home) project should use UTF-8 strings (implemented
I'm still trying to debug a very sneaky memory corruption problem. I came across
I've been trying to use Java's ProcessBuilder to launch an application in Linux that
I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18 I am trying to
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I'm trying to use memcache to handle session in PHP. I still want to
I'm trying to resolve an issue that I brought up at the end of
I'm still trying to get my head around LINQ and accessing a SQL Database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.