public static bool ConnectState(string path)
{
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 comand = "net use " + path;
proc.StandardInput.WriteLine(comand);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
string errormsg = proc.StandardError.ReadToEnd();
proc.StandardError.Close();
if (string.IsNullOrEmpty(errormsg))
{
flag = true;
}
else
{
throw new Exception(errormsg);
}
}
catch (Exception ex)
{
throw (ex);
}
finally
{
proc.Close();
proc.Dispose();
}
return flag;
}
public static void test012()
{
string path = @"\\192.168.18.9\anyone_common";
ConnectState(path);
Mat img = Cv2.ImRead("F:/001.bmp", 0);
Cv2.ImWrite(path + "\\" + "111.png", img);
}
static void Main(string[] args)
{
test012(); //局域网内的共享文件夹,访问
}