Solved

Map Network Drive Coding Options?

Posted on 2013-01-05
7
1,199 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
  • 3
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 305 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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