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

Map Network Drive Coding Options?

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
pointeman
Asked:
pointeman
  • 3
  • 3
1 Solution
 
käµfm³d 👽Commented:
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
 
dj_alikCommented:
0
 
käµfm³d 👽Commented:
@dj_alik

Maybe I'm not reading the post correctly. Isn't WNetAddConnection2 what I suggested?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
pointemanAuthor Commented:
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
 
käµfm³d 👽Commented:
Maybe I don't understand what you are asking then. From what you described, that is exactly what WNetAddConnection2 is for.
0
 
pointemanAuthor Commented:
I'm currently trying these suggestions. There is also a WNetAddConnection3.
0
 
pointemanAuthor Commented:
thx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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