public bool PathExists(bool throwException = false) { try { if (IsPathHasUserName & !IsUNC) { using (Tools.Impersonator i = new Tools.Impersonator(UserName, Domain, Password)) { return(Directory.Exists(Path)); } } else if (IsPathHasUserName & IsUNC) { ConnectToUNC(throwException); } return(Directory.Exists(Path)); } catch (Exception) { if (throwException) { throw; } else { return(false); } } }
public bool PathExists(bool throwException = false) { try { if (IsPathHasUserName & !IsUNC) { using (Tools.Impersonator i = new Tools.Impersonator(UserName, Domain, Password)) { return(Directory.Exists(Path)); } } else if (IsPathHasUserName & IsUNC) { ConnectToUNC(throwException); } return(Directory.Exists(Path)); } #pragma warning disable CS0168 // The variable 'er' is declared but never used catch (Exception er) #pragma warning restore CS0168 // The variable 'er' is declared but never used { if (throwException) { throw; } else { return(false); } } }
public string[] GetFileSystemEntries(string searchPattern = "*.*", SearchOption searchOption = SearchOption.TopDirectoryOnly) { if (IsPathHasUserName & !IsUNC) { using (Tools.Impersonator i = new Tools.Impersonator(UserName, Domain, Password)) { return(Directory.GetFileSystemEntries(Path, searchPattern, searchOption)); } } else if (IsPathHasUserName & IsUNC) { ConnectToUNC(false); } return(Directory.GetFileSystemEntries(Path, searchPattern, searchOption)); }
void SetUserAccount(string username, string password) { var cmd = string.Format("config {0} ", ServiceManager._FolderMonitorServiceName); if (txtusername.Enabled) { cmd += "obj= " + username + " "; cmd += "password= "******"obj= " + drpAccount.Text.Trim().Replace(" ", ""); } var process = new Process(); // process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; process.StartInfo.UseShellExecute = false; // process.StartInfo.LoadUserProfile = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = "sc"; process.StartInfo.Arguments = cmd; //string sc_data = ""; string sc_error = ""; //process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { sc_data = e.Data; }; //process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => { sc_error = e.Data; }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(2000); //if (!string.IsNullOrWhiteSpace(sc_error)) // throw new Exception(sc_error); //return sc_data; }