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

thru software as we do in the Explorer ?
rupak_khuranaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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...
jkrCommented:
One other thing that I forgot - you'll have to link with 'mpr.lib'
rupak_khuranaAuthor Commented:
I tried connecting and disconnecting too. Works pretty fine...Thanks a lot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.