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
Solved

c# Map Network Drive

Posted on 2013-01-19
3
4,711 Views
Last Modified: 2013-01-20
Hi,

I need to be able toautomatically map to a network drive using c# that includes user name and password. I'm currently using a batch file using NetUse but my customer doesn't like this solution even though it works fine.
0
Comment
Question by:naelyan
3 Comments
 
LVL 1

Accepted Solution

by:
bounty457 earned 500 total points
ID: 38796820
Hi,
you can use this:


private void Mapping_Click(object sender, EventArgs e)
        {
            MapNetDrive("X", @"\\192.168.0.112\vmware", "bounty", "pass");
         }

private void MapNetDrive(string driveChar, string server, string user, string password)
        
        {
            try
            {
                string path = string.Format("use {0}: {1} /user:{2} {3}", driveChar, server, user, password);
                Process proc = new Process();
                proc.StartInfo.FileName = "net";
                proc.StartInfo.Arguments = path;
                proc.StartInfo.UseShellExecute = false;
                proc.Start();
            }
            catch (Exception e)
            {
                               MessageBox.Show(e.ToString());
             }
        }

Open in new window


Regards Bounty
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38797794
0
 

Author Closing Comment

by:naelyan
ID: 38798026
Thank You
0

Featured Post

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.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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