473,883 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;

namespace TestOutboundMai n
{
/// <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.Componen tModel.Containe r 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
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
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.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(16, 24);
this.button1.Na me = "button1";
this.button1.Si ze = new System.Drawing. Size(120, 23);
this.button1.Ta bIndex = 0;
this.button1.Te xt = "Start Process";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// button2
//
this.button2.Lo cation = new System.Drawing. Point(16, 64);
this.button2.Na me = "button2";
this.button2.Si ze = new System.Drawing. Size(120, 23);
this.button2.Ta bIndex = 1;
this.button2.Te xt = "Kill Process";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_Click);
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(160, 64);
this.textBox1.N ame = "textBox1";
this.textBox1.T abIndex = 2;
this.textBox1.T ext = "0";
//
// button3
//
this.button3.Lo cation = new System.Drawing. Point(16, 104);
this.button3.Na me = "button3";
this.button3.Si ze = new System.Drawing. Size(120, 24);
this.button3.Ta bIndex = 3;
this.button3.Te xt = "Kill All Processes";
this.button3.Cl ick += new System.EventHan dler(this.butto n3_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(280, 149);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.button3,
this.textBox1,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

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

private void button1_Click(o bject sender, System.EventArg s e)
{
Process p = new Process();

p.StartInfo.Red irectStandardOu tput=false;

p.StartInfo.Fil eName =
@"C:\test\outbo undmain\TestOut boundMainConsol e.exe";
p.StartInfo.Arg uments = "Outbound" + count.ToString( );

p.StartInfo.Use ShellExecute = true;
p.Start();

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

count++;
}

private void button2_Click(o bject sender, System.EventArg s e)
{
try
{
//p.Kill();
Process tmpProcess = (Process)
arrOutProcess[Convert.ToInt32 (textBox1.Text)];
tmpProcess.Kill ();
// arrOutProcess.R emoveAt(i)
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}

}

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


Nov 15 '05 #1
1 2793
Set UseShellExecute in ProcessStartInf o to false, that should hide the
console window.

"Mullin Yu" <mu*******@ctil .com> wrote in message
news:eD******** ******@TK2MSFTN GP10.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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;

namespace TestOutboundMai n
{
/// <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.Componen tModel.Containe r 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
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
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.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(16, 24);
this.button1.Na me = "button1";
this.button1.Si ze = new System.Drawing. Size(120, 23);
this.button1.Ta bIndex = 0;
this.button1.Te xt = "Start Process";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// button2
//
this.button2.Lo cation = new System.Drawing. Point(16, 64);
this.button2.Na me = "button2";
this.button2.Si ze = new System.Drawing. Size(120, 23);
this.button2.Ta bIndex = 1;
this.button2.Te xt = "Kill Process";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_Click);
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(160, 64);
this.textBox1.N ame = "textBox1";
this.textBox1.T abIndex = 2;
this.textBox1.T ext = "0";
//
// button3
//
this.button3.Lo cation = new System.Drawing. Point(16, 104);
this.button3.Na me = "button3";
this.button3.Si ze = new System.Drawing. Size(120, 24);
this.button3.Ta bIndex = 3;
this.button3.Te xt = "Kill All Processes";
this.button3.Cl ick += new System.EventHan dler(this.butto n3_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(280, 149);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.button3,
this.textBox1,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

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

private void button1_Click(o bject sender, System.EventArg s e)
{
Process p = new Process();

p.StartInfo.Red irectStandardOu tput=false;

p.StartInfo.Fil eName =
@"C:\test\outbo undmain\TestOut boundMainConsol e.exe";
p.StartInfo.Arg uments = "Outbound" + count.ToString( );

p.StartInfo.Use ShellExecute = true;
p.Start();

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

count++;
}

private void button2_Click(o bject sender, System.EventArg s e)
{
try
{
//p.Kill();
Process tmpProcess = (Process)
arrOutProcess[Convert.ToInt32 (textBox1.Text)];
tmpProcess.Kill ();
// arrOutProcess.R emoveAt(i)
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}

}

private void button3_Click(o bject sender, System.EventArg s 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
4902
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
1
2710
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 it for sure. When I fire some command from my C# program to this exe, I get the response for ALMOST all the commands perfectly. BUT For a few commands, my program sometimes gives the desired output, and sometimes only half of it. (as it gives at...
6
3242
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 I have all the code set up to do this, however when I issue a Console.WriteLine instruction, nothing gets written to the console. In fact, the command prompt comes back before the program has finished executing. What do I need to do?
11
29762
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. The value returned by the Main function has no impact on the value returned by the application. Windows applications exit immediately, leaving their windows still open. Is there a way to change the value a Windows application exits with. Basically...
2
2258
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 btnStartApp(object sender, System.EventArgs e) { Process procID; string procName; ProcessStartInfo psi = new ProcessStartInfo();
3
6286
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 h:\finance\" & username & "\" & "+Common /G " & username & ":R", AppWinStyle.Hide, True) End Sub
4
1630
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 = New Process psSession.StartInfo.FileName = path\to\pcomstrt.exe psSession.StartInfo.Arguments = "/P="path\to\ws file & " /S=X /Q" The /P specifies the .ws file to load, the /S=X specifies that the session letter should be X, and i forgot what...
4
10523
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 doesn't seem to write to the screen in the way I would expect. The output is:
1
17365
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 and has an example? I am expecting it would look something like below... // Execute the first command proc.StartInfo.FileName = @"cmd.exe"; proc.StartInfo.Arguments = @"dir";
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7129
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.