Access remote directory

 

 

 

 

 

     /// <Summary>   
        /// connect the remote shared folder   
        /// </ Summary>   
        /// <param name = "path"> Path </ param> Remote shared folder   
        /// <param name = " userName "> username </ param>   
        /// <param name =" passWord, "> password </ param>   
        /// <Returns> </ Returns>   
        public static BOOL connectState (String path, the userName String, String passWord,) 
        { 
            In Flag to false = BOOL; 
            Process proc = new new Process (); 
            the try 
            { 
                proc.StartInfo.FileName = "cmd.exe"; 
                proc.StartInfo.UseShellExecute = to false;
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.CreateNoWindow = true;
                proc.Start();
                proc.StandardInput.WriteLine("net use * /del /y");
                string dosLine = "net use " + path + " " + passWord + " /user:" + userName;
                proc.StandardInput.WriteLine(dosLine);
                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;
        }

  

Guess you like

Origin www.cnblogs.com/lhlong/p/11208877.html