Solved

c# Map Network Drive

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

Expert Comment

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

Author Closing Comment

by:naelyan
ID: 38798026
Thank You
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

13 Experts available now in Live!

Get 1:1 Help Now