473,396 Members | 1,987 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,396 software developers and data experts.

Windows Application - attach to the existing console

Hi there,

I wrote an app that has GUI but also accepts command line parameters
for automated execution.
When the app is started from command line with parameters, I'd like the
application to behave like a Console Application, e.g.
* the command prompt should not return right away but only once the
application quits
* Console.Write() should write into the console

Is this possible? e.g. via .NET SDK or PInvoke/Win32?

Thanks,
-Oleg.

Dec 11 '06 #1
3 2155
Hello Oleg,

OOI wrote an app that has GUI but also accepts command line parameters
OOfor automated execution.
OOWhen the app is started from command line with parameters, I'd like
OOthe
OOapplication to behave like a Console Application, e.g.

What should happen to GUI?

OO* the command prompt should not return right away but only once
OOthe
OOapplication quits
OO* Console.Write() should write into the console
OOIs this possible? e.g. via .NET SDK or PInvoke/Win32?

I think that u need to look at AttachConsole API

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 11 '06 #2
have a condition in ur Main(), based on which u show the GUI.
something like this
Main()
{
if(showGui) //if command line args contains flag
{
Application.Run(mainForm())
}
else
{
//run as service mode without any UI
}
}
Michael Nemtsev wrote:
Hello Oleg,

OOI wrote an app that has GUI but also accepts command line parameters
OOfor automated execution.
OOWhen the app is started from command line with parameters, I'd like
OOthe
OOapplication to behave like a Console Application, e.g.

What should happen to GUI?

OO* the command prompt should not return right away but only once
OOthe
OOapplication quits
OO* Console.Write() should write into the console
OOIs this possible? e.g. via .NET SDK or PInvoke/Win32?

I think that u need to look at AttachConsole API

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 12 '06 #3

Michael Nemtsev wrote:
I think that u need to look at AttachConsole API
....and/or AllocConsole and FreeConsole. You may have to map the
Console.Out stream into the console window you attached with
AttachConsole. I believe I have gotten this work before, but I cannot
remember exactly what I did. I think the Console.Out stream will map
into a new console created by AllocConsole automatically, but don't
take my word for it. The problem with AllocConsole is that it will
create a brand new console window even if the application is launched
from an existing console window. That can be annoying depending on how
you want it to work.

Dec 12 '06 #4

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

Similar topics

3
by: Steven Fox | last post by:
============================================================ About DB2 Administration Tools Environment ============================================================ DB2 administration tools level:...
2
by: Fan Wang | last post by:
Hi All, I wrote a windows service with C# as below. But I can't install it with installutil.exe. I got an error message " Exception occurred while initializing the installation:...
4
by: reachsamdurai | last post by:
Hello, Can you please let me know the procedure to reach db2 command prompt from a cygwin window (hence without using Start-> Run -> db2cmd method). I'm planning to write shell scripts which...
2
by: MATT | last post by:
I am trying to create a windows service. The part I am having trouble with is writing text to a log file. I am using a very basic StreamWriter function to try to test this. I have created a...
2
by: Elioth | last post by:
Hi, How I Debug a Windows Services in VB 2005? Thanks for all help. Elioth
9
by: garyusenet | last post by:
I am using a C# solution that somebody kindly sent me. It was a console application. I am trying to get use of the MessageBox. I have added the following using directive to the namespaces at...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
4
by: emanuelanechei | last post by:
These days i'm creating a windows service in c# which reads some data from a file and saves it in a database. The data in the file changes every minute. I am using FileSystemWatcher object which...
4
by: Propad | last post by:
Hello, I know this issue pops up once in a while, but I haven't found a good answer to it. I need to debug a long running application under windows. The application is a combined java/python...
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: 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
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
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...
0
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.