求c#关于映射网络磁盘的代码

来源:百度知道 编辑:UC知道 时间:2024/05/13 09:32:39
我的数据库地址地址 \\192.168.1.26\\数据库\\book.mdb
现在我需要在winform(c#)应用程序中用到里面的数据,所以需要先将以上地址映射到本地..请问映射到本地的c#代码怎么写?谢谢~

private void button1_Click(object sender, System.EventArgs e)
{
string cmdtext = "net use h: 192.168.1.26数据库$ "密码" /user:"帐号";//把数据库$共享映射到本地H盘
Process MyProcess= new Process();
//设定程序名
MyProcess.StartInfo.FileName = "cmd.exe";
//关闭Shell的使用
MyProcess.StartInfo.UseShellExecute = false;
//重定向标准输入
MyProcess.StartInfo.RedirectStandardInput = true;
//重定向标准输出
MyProcess.StartInfo.RedirectStandardOutput = true;
//重定向错误输出
MyProcess.StartInfo.RedirectStandardError = true;
//设置不显示窗口
MyProcess.StartInfo.CreateNoWindow = true;
//执行VER命令
MyProcess.Start();
MyProcess.StandardInput.WriteLine(cmdtext);
MyProcess.StandardInput.WriteLine("exit");
//从输出流获取命令执行结果,
string exepath = Application.StartupPath;
//把返回的DOS信息读出来
StrInfo=MyProcess.StandardOutput.ReadToEnd();
this.textBox1.Text = StrInfo;