using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Yaulw.Other { /// /// Commonly used Batch/CMD command Line Command /// public static class CMDcommands { #region CMDCommands /// /// map a credential to a network path /// /// network path /// user /// password /// Command-Line Command static public string net_use(string path, string user, string pwd) { return ("net use " + path + " /User:" + user + " " + pwd); } /// /// map a credential and drive letter to a network path /// /// network path /// drive letter to map /// user /// password /// /// Command-Line Command static public string net_use_persist(string path, string driveletter, string user, string pwd) { return ("net use " + driveletter + ": " + path + " /User:" + user + " " + pwd + " PERSISTENT:YES"); } /// /// Delete a Network Credential from a network path /// /// network path /// Command-Line Command static public string net_delete(string path) { return ("net use /delete " + path); } /// /// Delete a Drive Letter and Network Credential from a network path /// /// /// Command-Line Command static public string net_delete_persist(string driveletter) { return ("net use /delete " + driveletter + ":"); } #endregion #region PSTools /// /// Commands for System Internals PSExec Tools /// public static class PSTools { /// /// PSExec is a System Internals Remote Execution CommandLine tool. /// Use this to execute a .bat/.cmd file on the other computer /// /// Name of computer /// .bat or .cmd file to execute /// user /// password /// true to allow remote process to interact with desktop /// Command-Line Command static public string ps_exec(string computer, string file, string user, string pwd, bool interactive) { string Show = ""; if (interactive) Show = "-i "; if (file.ToLower().Contains(".bat") || file.ToLower().Contains(".cmd")) { // copy .bat or .cmd file over return (@"psexec.exe \\" + computer + " -u " + user + " -p " + pwd + " -c -f -e -d " + Show + "/accepteula " + '\"' + file + '\"'); } else { // doesn't copy over, executes command from location, don't wait for process to terminate return (@"psexec.exe \\" + computer + " -u " + user + " -p " + pwd + " -d -e " + Show + "/accepteula " + '\"' + file + '\"'); } } } #endregion } }