Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1675
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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