Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Map Network Drive Coding Options?

Posted on 2013-01-05
7
Medium Priority
?
1,421 Views
Last Modified: 2013-01-12
Q. Which is the most reliable way to map a network drive on either local or remote drive?

I generally use the Process class and run the Net Use command. I think this can also be accomplished within c# using Netsh or Powershell, etc...
0
Comment
Question by:pointeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1220 total points
ID: 38747016
You can use the WNetAddConnection2 WinAPI function to map drives programmatically. Use WNetCancelConnection to un-map a driver. The P/Invoke code can be found here:

http://www.pinvoke.net/default.aspx/mpr/WNetAddConnection2.html
http://www.pinvoke.net/default.aspx/mpr/WNetCancelConnection2.html

Keep in mind, though, that (AFAIK) mapping a drive is really more of a convenience to the user, rather than your application. Mapping a drive gives you an association to a drive letter, but using a UNC path (which is what you pass when you map a drive) is just as simple (programmatically) as using a drive letter.
0
 
LVL 18

Expert Comment

by:dj_alik
ID: 38747150
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38747349
@dj_alik

Maybe I'm not reading the post correctly. Isn't WNetAddConnection2 what I suggested?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pointeman
ID: 38747411
I can manually Map the network drive share using the built-in Windows 7 'Add network share' window. This is what I'm looking to do, except programmatically.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38748086
Maybe I don't understand what you are asking then. From what you described, that is exactly what WNetAddConnection2 is for.
0
 

Author Comment

by:pointeman
ID: 38748294
I'm currently trying these suggestions. There is also a WNetAddConnection3.
0
 

Author Closing Comment

by:pointeman
ID: 38770926
thx
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question