嗨,我正在使用Visual Studio 2012终极版的Windows窗体应用程序,如果单击按钮,如何映射特定的网络驱动器? [英] Hi, I am using windows Form application with Visual studios 2012 ultimate, How do I go about mapping a specific network drive if a button has been click?

查看:106
本文介绍了嗨,我正在使用Visual Studio 2012终极版的Windows窗体应用程序,如果单击按钮,如何映射特定的网络驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (hasPublic)
            {
            //map drive
            //I am not sure of the lines to write so that I can map a specific
            //Network drive once the button has been clicked

推荐答案

为什么不使用适当的 net use 命令 - 所以 Process.Start ...



所以这里是一个可运行的示例 - 只需用实际网络共享替换服务器和共享:



Why not just call a command line with appropiate net use command - so Process.Start...

So here is an runnable example - just replace Server and Share with real network share:

using System.Diagnostics;

namespace MapNetworkDrive
{
    class Program
    {
        static void Main(string[] args)
        {
            string strCommand = @"net use X: \\Server\Share";

            Process.Start("CMD.exe", "/C \"" + strCommand + "\"");
        }
    }
}





所以我的想法就是调用commandprompt(cmd.exe) )使用net use命令创建映射。所以Process.Start用于运行命令提示。



P.S.如果您不想看到cmd-Window,请使用



So the idea is to call the commandprompt (cmd.exe) with the net use command to create the mapping. So Process.Start is used to run the commandprompt.

P.S. If you don't want to see the cmd-Window use

startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;





我希望这能解决你的问题!



I hope this solves your Problem!


这篇关于嗨,我正在使用Visual Studio 2012终极版的Windows窗体应用程序,如果单击按钮,如何映射特定的网络驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆