怎么用C#访问共享文件夹
答案:4 悬赏:80 手机版
解决时间 2021-11-10 05:21
- 提问者网友:饥饿走向夜
- 2021-11-09 16:42
怎么用C#访问共享文件夹
最佳答案
- 五星知识达人网友:渊鱼
- 2021-11-09 17:02
public static bool Connect(string remoteHost, string userName, string passWord)
{
bool Flag = false;
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = "net use " + remoteHost + " " + passWord + " /user:" + userName;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
string errormsg = proc.StandardError.ReadToEnd();
WriteLog.WirteDayLog("msg:" + errormsg);
proc.StandardError.Close();
if (String.IsNullOrEmpty(errormsg))
{
Flag = true;
}
}
catch (Exception ex)
{
WriteLog.WirteDayLog(ex.ToString());
throw ex;
}
finally
{
proc.Close();
proc.Dispose();
}
return Flag;
}
Connect(@"\\192.168.15.90", "administrator", "123")追问程序我运行了但是没有任何反应。我想要打开共享的文件夹。我在程序里有些了个
string dosLine1 = "explorer " + remoteHost; proc.StandardInput.WriteLine(dosLine1);就好了。但是有个代码我没不知道是啥 ,WriteLog是啥啊。在哪定义的
求高手在指点指点呗。谢谢追答WriteLog是我记错误日志的方法,你删掉就好了
{
bool Flag = false;
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = "net use " + remoteHost + " " + passWord + " /user:" + userName;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
string errormsg = proc.StandardError.ReadToEnd();
WriteLog.WirteDayLog("msg:" + errormsg);
proc.StandardError.Close();
if (String.IsNullOrEmpty(errormsg))
{
Flag = true;
}
}
catch (Exception ex)
{
WriteLog.WirteDayLog(ex.ToString());
throw ex;
}
finally
{
proc.Close();
proc.Dispose();
}
return Flag;
}
Connect(@"\\192.168.15.90", "administrator", "123")追问程序我运行了但是没有任何反应。我想要打开共享的文件夹。我在程序里有些了个
string dosLine1 = "explorer " + remoteHost; proc.StandardInput.WriteLine(dosLine1);就好了。但是有个代码我没不知道是啥 ,WriteLog是啥啊。在哪定义的
求高手在指点指点呗。谢谢追答WriteLog是我记错误日志的方法,你删掉就好了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯