Avant de dire que c'est une question en double, laissez-moi vous expliquer (comme j'ai lu tous les sujets similaires).Masquer la fenêtre de commande en C# Application
Mon application a ces deux paramètres:
procStartInfo.CreateNoWindow = true;
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
et est a aussi WindowsApplication que le type de sortie.
La fenêtre noire apparaît quand j'appelle une commande de ligne de commande. Y a-t-il autre chose que je puisse faire pour cacher la fenêtre? Cela ne se produit pas pour toutes les commandes, XCOPY est une situation où la fenêtre noire clignote. Cela ne se produit que lorsque la destination que je suis XCOPYing contient déjà le fichier et il me demande si je veux le remplacer. Même si je passe/Y, il clignotera encore brièvement.
Je suis ouvert à l'utilisation de vbscript si cela peut aider, mais d'autres idées?
Le client va appeler mon exécutable, puis passer dans une commande de ligne de commande par exemple:
C:\MyProgram.exe start XCOPY c:\Test.txt c:\ProgramFiles\
Voici le code complet de l'application:
class Program
{
static void Main(string[] args)
{
string command = GetCommandLineArugments(args);
// /c tells cmd that we want it to execute the command that follows and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = procStartInfo;
process.Start();
}
private static string GetCommandLineArugments(string[] args)
{
string retVal = string.Empty;
foreach (string arg in args)
retVal += " " + arg;
return retVal;
}
}
Pouvez-vous poster le reste de votre 'processus' /' ProcessStartInfo' c ode? –
@fletcher: Il est indiqué dans la question que le type de sortie est Windows Application et non la console. Je l'ai testé avec le type de sortie défini sur l'application Windows et cela fonctionne très bien. @snow: Je vérifierais votre paramètre OutputType. – nukefusion
@fletcher C'est en fait un peu le problème! Je voudrais que la fenêtre ne s'affiche pas du tout! – mint