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);
}
///
/// 關(guān)閉所有共享連接
///
public static void KillAllLink()
{
string cKillCmd = @"Net Use /delete * /yes";
CallCmd(cKillCmd);
}
///
/// 關(guān)閉指定連接
///
/// 共享路徑
public static void KillLink(string path)
{
string cKillCmd = @"Net Use " + path + " /delete /yes";
CallCmd(cKillCmd);
}
///
/// 調(diào)用Cmd命令
///
/// 命令行參數(shù)
private static void CallCmd(string strCmd)
{
//調(diào)用cmd命令
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/c " + strCmd;
myProcess.StartInfo.UseShellExecute = false; //關(guān)閉Shell的使用
myProcess.StartInfo.RedirectStandardInput = true; //重定向標(biāo)準(zhǔn)輸入
myProcess.StartInfo.RedirectStandardOutput = true; //重定向標(biāo)準(zhǔn)輸出
myProcess.StartInfo.RedirectStandardError = true; //重定向錯(cuò)誤輸出
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch { }
finally
{
myProcess.WaitForExit();
if (myProcess != null)
{
myProcess.Close();
}
}
}
}
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的c#客户端 通过用户名密码访问服务器文件,C#如何连接服务器共享文件夹的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 服务器内存使用率高找不到是哪个进程,内存
- 下一篇: 未转变者服务器床id,最新id欢迎补充