PC Review


Reply
Thread Tools Rate Thread

Can I use Process to execute a console application without showing the command prompt

 
 
Mullin Yu
Guest
Posts: n/a
 
      29th Nov 2003
But, I want is that I can have a Main app that will start a new process or
kill one particular or all process. The process will open a console exe.
But, I don't want the user to close the console windows by themselves, and
force them to use the Main app.

If I use Windows Services, I'm not sure can I create one dynamically, and
then kill easily. But, if using console application, my following coding is
working now.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;

namespace TestOutboundMain
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

private System.Windows.Forms.Button button2;

ArrayList arrOutProcess = new ArrayList();
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button3;
int count = 0;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Start Process";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 64);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 23);
this.button2.TabIndex = 1;
this.button2.Text = "Kill Process";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(160, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 2;
this.textBox1.Text = "0";
//
// button3
//
this.button3.Location = new System.Drawing.Point(16, 104);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(120, 24);
this.button3.TabIndex = 3;
this.button3.Text = "Kill All Processes";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(280, 149);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button3,
this.textBox1,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
Process p = new Process();

p.StartInfo.RedirectStandardOutput=false;

p.StartInfo.FileName =
@"C:\test\outboundmain\TestOutboundMainConsole.exe";
p.StartInfo.Arguments = "Outbound" + count.ToString();

p.StartInfo.UseShellExecute = true;
p.Start();

// Add to ArrayList
arrOutProcess.Add(p);

count++;
}

private void button2_Click(object sender, System.EventArgs e)
{
try
{
//p.Kill();
Process tmpProcess = (Process)
arrOutProcess[Convert.ToInt32(textBox1.Text)];
tmpProcess.Kill();
// arrOutProcess.RemoveAt(i)
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

}

private void button3_Click(object sender, System.EventArgs e)
{
for(int i=0; i<count; i++)
{
Process tmpProcess = (Process) arrOutProcess[i];
if(!tmpProcess.HasExited)
{
tmpProcess.Kill();
}
}
}


}
}




 
Reply With Quote
 
 
 
 
Daniel O'Connell
Guest
Posts: n/a
 
      29th Nov 2003
Set UseShellExecute in ProcessStartInfo to false, that should hide the
console window.

"Mullin Yu" <(E-Mail Removed)> wrote in message
news:eD$(E-Mail Removed)...
> But, I want is that I can have a Main app that will start a new process or
> kill one particular or all process. The process will open a console exe.
> But, I don't want the user to close the console windows by themselves, and
> force them to use the Main app.
>
> If I use Windows Services, I'm not sure can I create one dynamically, and
> then kill easily. But, if using console application, my following coding

is
> working now.
>
> using System;
> using System.Drawing;
> using System.Collections;
> using System.ComponentModel;
> using System.Windows.Forms;
> using System.Data;
> using System.Diagnostics;
>
> namespace TestOutboundMain
> {
> /// <summary>
> /// Summary description for Form1.
> /// </summary>
> public class Form1 : System.Windows.Forms.Form
> {
> private System.Windows.Forms.Button button1;
> /// <summary>
> /// Required designer variable.
> /// </summary>
> private System.ComponentModel.Container components = null;
>
> private System.Windows.Forms.Button button2;
>
> ArrayList arrOutProcess = new ArrayList();
> private System.Windows.Forms.TextBox textBox1;
> private System.Windows.Forms.Button button3;
> int count = 0;
>
> public Form1()
> {
> //
> // Required for Windows Form Designer support
> //
> InitializeComponent();
>
> //
> // TODO: Add any constructor code after InitializeComponent call
> //
> }
>
> /// <summary>
> /// Clean up any resources being used.
> /// </summary>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if (components != null)
> {
> components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
>
> #region Windows Form Designer generated code
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.button1 = new System.Windows.Forms.Button();
> this.button2 = new System.Windows.Forms.Button();
> this.textBox1 = new System.Windows.Forms.TextBox();
> this.button3 = new System.Windows.Forms.Button();
> this.SuspendLayout();
> //
> // button1
> //
> this.button1.Location = new System.Drawing.Point(16, 24);
> this.button1.Name = "button1";
> this.button1.Size = new System.Drawing.Size(120, 23);
> this.button1.TabIndex = 0;
> this.button1.Text = "Start Process";
> this.button1.Click += new System.EventHandler(this.button1_Click);
> //
> // button2
> //
> this.button2.Location = new System.Drawing.Point(16, 64);
> this.button2.Name = "button2";
> this.button2.Size = new System.Drawing.Size(120, 23);
> this.button2.TabIndex = 1;
> this.button2.Text = "Kill Process";
> this.button2.Click += new System.EventHandler(this.button2_Click);
> //
> // textBox1
> //
> this.textBox1.Location = new System.Drawing.Point(160, 64);
> this.textBox1.Name = "textBox1";
> this.textBox1.TabIndex = 2;
> this.textBox1.Text = "0";
> //
> // button3
> //
> this.button3.Location = new System.Drawing.Point(16, 104);
> this.button3.Name = "button3";
> this.button3.Size = new System.Drawing.Size(120, 24);
> this.button3.TabIndex = 3;
> this.button3.Text = "Kill All Processes";
> this.button3.Click += new System.EventHandler(this.button3_Click);
> //
> // Form1
> //
> this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> this.ClientSize = new System.Drawing.Size(280, 149);
> this.Controls.AddRange(new System.Windows.Forms.Control[] {
> this.button3,
> this.textBox1,
> this.button2,
> this.button1});
> this.Name = "Form1";
> this.Text = "Form1";
> this.ResumeLayout(false);
>
> }
> #endregion
>
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main()
> {
> Application.Run(new Form1());
> }
>
> private void button1_Click(object sender, System.EventArgs e)
> {
> Process p = new Process();
>
> p.StartInfo.RedirectStandardOutput=false;
>
> p.StartInfo.FileName =
> @"C:\test\outboundmain\TestOutboundMainConsole.exe";
> p.StartInfo.Arguments = "Outbound" + count.ToString();
>
> p.StartInfo.UseShellExecute = true;
> p.Start();
>
> // Add to ArrayList
> arrOutProcess.Add(p);
>
> count++;
> }
>
> private void button2_Click(object sender, System.EventArgs e)
> {
> try
> {
> //p.Kill();
> Process tmpProcess = (Process)
> arrOutProcess[Convert.ToInt32(textBox1.Text)];
> tmpProcess.Kill();
> // arrOutProcess.RemoveAt(i)
> }
> catch(Exception ex)
> {
> Console.WriteLine(ex.Message);
> }
>
> }
>
> private void button3_Click(object sender, System.EventArgs e)
> {
> for(int i=0; i<count; i++)
> {
> Process tmpProcess = (Process) arrOutProcess[i];
> if(!tmpProcess.HasExited)
> {
> tmpProcess.Kill();
> }
> }
> }
>
>
> }
> }
>
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WIN32 Windows Application Outputting to Command Prompt as if a Console Program - How? Peter Nimmo Microsoft VC .NET 4 22nd Jun 2007 03:26 AM
NO COMMAND PROMPT OR RECOVERY CONSOLE PROMPT =?Utf-8?B?QV9EVUI=?= Windows XP Performance 1 6th Aug 2006 09:06 PM
stop command prompt from showing up for new process Zamil Microsoft C# .NET 3 13th Mar 2005 04:48 AM
How can I execute a command in the command prompt using Visual Bas =?Utf-8?B?RWR1YXJkbzc4?= Microsoft Dot NET 0 16th Jan 2005 05:41 AM
Recovery Console execute command,Do any one know it? manbamgo Microsoft Windows 2000 New Users 0 25th Sep 2003 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:48 PM.