473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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();
}
}
}
}
}


Nov 15 '05 #1
1 2696
Set UseShellExecute in ProcessStartInfo to false, that should hide the
console window.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl...
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();
}
}
}
}
}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
1
by: Div / | last post by:
I have a very strange problem here. I have a wrapper class for a command line MyProgram.exe. When i run it from the command prompt (MyProgram.exe), it runs perfectly. So there is not problem with...
6
by: Mark Allison | last post by:
Hi, I have an application that I want to be to run in Console mode and GUI mode. If no params are entered, I want the GUI fired up, if params are entered, then go into console mode. I believe...
11
by: Peter Steele | last post by:
I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application, there doesn't seem to be a way to control this....
2
by: PMac | last post by:
I'm trying to execute a stand-alone console application from an aspx page when a use clicks a button on that page. On the aspx page is the following lines of pertinent code: private void...
3
by: David Eadie | last post by:
G'Day all, I cant for the God in me work out how to execute the following command line in vb.net: (watch for the word wrapping also) Sub(ByVal username As String) Shell("ECHO Y| cacls...
4
by: Kevin | last post by:
I have an application that handles datascraping with a TN3270 session. The TN3270 session is opened with a .ws profile and pcomstrt.exe. The process string in the application is this: psSession...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
1
by: stemp1ar | last post by:
I am wondering if it possible to open a single process and run multiple commands on that process and check standard error and standard out after each command? Has anyone done something similar...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.