• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

How to Map Network Drives ........

thru software as we do in the Explorer ?
0
rupak_khurana
Asked:
rupak_khurana
  • 3
1 Solution
 
jkrCommented:
Use the following code


    NETRESOURCE nr;

    ZeroMemory  (   &nr,    sizeof  (   NETRESOURCE));

    nr.dwType           =   RESOURCETYPE_DISK;
    nr.lpLocalName      =   L""; // use a drive letter like "L:" to map it to a local drive
    nr.lpRemoteName     =   "\\\\server\\share";


    dwRes   =   WNetAddConnection2  (   &nr,
                                        "Password",
                                        "User",
                                        0
                                    );

"Password" and "User" can be set to NULL to use the account information of the logged-on user.

Feel free to ask if you need more information!
0
 
jkrCommented:
Ooops, correction - the above code is partly UNICODE, use


    nr.dwType           =   RESOURCETYPE_DISK;
    nr.lpLocalName      =   ""; // use a drive letter like "L:" to map it to a local drive
    nr.lpRemoteName     =   "\\\\server\\share";

instead - sorry...
0
 
jkrCommented:
One other thing that I forgot - you'll have to link with 'mpr.lib'
0
 
rupak_khuranaAuthor Commented:
I tried connecting and disconnecting too. Works pretty fine...Thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now