Solved

Map Network Drive Coding Options?

Posted on 2013-01-05
7
1,043 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 74

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 74

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 74

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now