ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "mysql"; psi.Arguments = "-h localhost -u root -proot awtt"; psi.WorkingDirectory = @"C:\Programmes\MySQL\MySQL Server 5.5\bin"; Process proc = Process.Start(psi);
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "PsExec"; psi.Arguments = "ipconfig"; psi.WorkingDirectory = @"C:\Windows\System32"; Process.Start(psi);
ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "PsExec.exe"; psi.Arguments = "\\\\PCHP013 b.bat"; psi.WorkingDirectory = @"C:\Temp\Nouveau dossier"; proc = Process.Start(psi);
\t correspond à une tabulation \n correspond à un saut de ligne \0 correspond à la fin de la chaîne de caractère \\ correspond à la représentation d'un backslash
> psexec \\PC app.exe
string pse = "psexec \\\\PC app.exe";
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void onoff_CheckedChanged(object sender, EventArgs e) { if (onoff.Checked == true) { login.ReadOnly = false; mdp.ReadOnly = false; } else { login.ReadOnly = true; mdp.ReadOnly = true; } } private void psexec_CheckedChanged(object sender, EventArgs e) { if (psexec.Checked == true) { arguments.ReadOnly = false; valider.Visible = true; } else { arguments.ReadOnly = true; } } //DEBUT DU PROGRAMME APRES CLICK SUR VALIDER private void valider_Click(object sender, EventArgs e) { //Varibales string Sip = ip.Text; string Slogin = login.Text; string Smdp = mdp.Text; string Sargu = arguments.Text; //Psexec ################################################################################### if (psexec.Checked true && onoff.Checked true) { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "PsExec.exe"; psi.Arguments = "\\\"+Sip+" -u "+Slogin+" -p "+Smdp+" "+Sargu; psi.WorkingDirectory = @"C:\Windows\Temp\psexec"; Process.Start(psi); } else { //Processus startinfo ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.WorkingDirectory = @"C:\Windows\Temp\psexec"; processStartInfo.FileName = "PsExec.exe"; processStartInfo.Arguments = "\\\" + Sip + " " + Sargu; processStartInfo.UseShellExecute = false; processStartInfo.RedirectStandardInput = true; processStartInfo.RedirectStandardOutput = true; //Lance le processus Process process = new Process(); process.StartInfo = processStartInfo; bool processStarted = process.Start(); //Renvoie les données StreamReader outputReader = process.StandardOutput; process.WaitForExit(); //Affiche le resultat string displayText = "Output" + Environment.NewLine + "==============" + Environment.NewLine; displayText += outputReader.ReadToEnd(); displayText += Environment.NewLine + "==============" + Environment.NewLine; resultat.Text = displayText; }
processStartInfo.UseShellExecute = false; processStartInfo.RedirectStandardInput = true; processStartInfo.RedirectStandardOutput = true;
psexec.Checked = true
processStartInfo.FileName = "C:\\psexefolder\\psexec.exe";
When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used only by the process that is started and has meaning only within the context of the new process. When UseShellExecute is false, the FileName property must be a fully qualified path to the executable.