这篇文章主要为大家详细介绍了C#如何连接服务器共享文件夹,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了C#连接服务器共享文件夹的具体代码,供大家参考,具体内容如下
public class ClassConnWin { ////// 连接共享文件夹 /// /// 共享路径 /// 用户名 /// 密码 ///public static void linkFile(string path, string user, string pass) { string cLinkUrl = @"Net Use " + path + " " + pass + " /user:" + user; CallCmd(cLinkUrl); } /// /// 关闭所有共享连接 /// public static void KillAllLink() { string cKillCmd = @"Net Use /delete * /yes"; CallCmd(cKillCmd); } ////// 关闭指定连接 /// /// 共享路径 public static void KillLink(string path) { string cKillCmd = @"Net Use " + path + " /delete /yes"; CallCmd(cKillCmd); } ////// 调用Cmd命令 /// /// 命令行参数 private static void CallCmd(string strCmd) { //调用cmd命令 Process myProcess = new Process(); try { myProcess.StartInfo.FileName = "cmd.exe"; myProcess.StartInfo.Arguments = "/c " + strCmd; myProcess.StartInfo.UseShellExecute = false; //关闭Shell的使用 myProcess.StartInfo.RedirectStandardInput = true; //重定向标准输入 myProcess.StartInfo.RedirectStandardOutput = true; //重定向标准输出 myProcess.StartInfo.RedirectStandardError = true; //重定向错误输出 myProcess.StartInfo.CreateNoWindow = true; myProcess.Start(); } catch { } finally { myProcess.WaitForExit(); if (myProcess != null) { myProcess.Close(); } } } }
以上就是C#如何连接服务器共享文件夹的详细内容,更多请关注0133技术站其它相关文章!