C#如何连接服务器共享件夹本⽂实例为⼤家分享了C#连接服务器共享⽂件夹的具体代码,供⼤家参考,具体内容如下public class ClassConnWin
{
/// <summary>
/// 连接共享⽂件夹
/// </summary>
/// <param name="path">共享路径</param>
/// <param name="user">⽤户名</param>
/// <param name="pass">密码</param>
/// <returns></returns>
public static void linkFile(string path, string user, string pass)
{
string cLinkUrl = @"Net Use " + path + " " + pass + " /user:" + user;
CallCmd(cLinkUrl);
}
/// <summary>
/// 关闭所有共享连接
/// </summary>
public static void KillAllLink()
{
string cKillCmd = @"Net Use /delete * /yes";
CallCmd(cKillCmd);
}
/
// <summary>
/// 关闭指定连接
/// </summary>
/// <param name="path">共享路径</param>
public static void KillLink(string path)
{
string cKillCmd = @"Net Use " + path + " /delete /yes";
CallCmd(cKillCmd);
如何共享文件夹}
/// <summary>
/// 调⽤Cmd命令
/
// </summary>
/// <param name="strCmd">命令⾏参数</param>
private static void CallCmd(string strCmd)
{
//调⽤cmd命令
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName = "";
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();
}
}
}
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。