Solved

c# Map Network Drive

Posted on 2013-01-19
3
4,884 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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