Bonjour à tous
Voila mon problème; j'essaye d'executer une commande PsExec à partir d'un programme C#.
Voici le code :
Le programme lève une exception dès l'appel de Process.Start, cela fonctionnait très bien depuis une semaine et ce n'est pas la première fois que le problème se pose; il survient a priori de manière assez aléatoire et je ne vois vraiment pas d'où peut venir ce problème
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 int exitCode; string cmd = @"\\" + host + @" -u mondomaine\" + login + " -p " + passwordclear + " -c " + path; // Prepare the process to run ProcessStartInfo start = new ProcessStartInfo(); start.Domain = "mondomaine"; start.UserName = login; start.Password = password; start.UseShellExecute = false; start.WorkingDirectory = System.IO.Path.GetDirectoryName(path); // Enter in the command line arguments, everything you would enter after the executable name itself start.Arguments = cmd; // Enter the executable to run, including the complete path start.FileName = "psexec"; // Do you want to show a console window? start.WindowStyle = ProcessWindowStyle.Hidden; start.CreateNoWindow = true; // Run the external process & wait for it to finish try { using (Process proc = Process.Start(start)) { proc.WaitForExit(); // Retrieve the app's exit code exitCode = proc.ExitCode; } switch (exitCode.ToString()) { case "0": MessageBox.Show("Success", "Success"); break; case "53": MessageBox.Show("Error 53 : The network path was not found.", "Error"); break; case "2250": MessageBox.Show("Error 2250 : This network connection does not exist.", "Error"); break; case "161": MessageBox.Show("Error 161: The specified path is invalid.", "Error"); break; case "1326": MessageBox.Show("Error 1326 : Logon failure: unknown user name or bad password.", "Error"); break; default: MessageBox.Show("Error " + exitCode.ToString()); break; } } catch (Exception ex) { MessageBox.Show("Unknown Exception" + Environment.NewLine + ex.Message, "Caution"); }
Le compte devant lancer le programme est un compte administrateur sur un domaine active directory, à executer sur un poste distant avec une session ouverte par un utilisateur standard
Une idée ?![]()
Partager