473,721 Members | 4,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command line interface and Windows form in same program

Jwe
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line to
return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and display
a message. This is working correctly.

If the correct number of arguments is supplied it should display
the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows Application'
and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.
Feb 8 '08 #1
7 9366
Jwe
If the correct number of arguments is supplied it should display
the command help. This is working correctly.

should be:

If an incorrect number of arguments is supplied it should display
the command help. This is working correctly.

"Jwe" <jw*@mail.comwr ote in message
news:ce******** *************** *******@pipex.n et...
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line
to return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and
display a message. This is working correctly.

If the correct number of arguments is supplied it should
display the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows
Application' and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the
help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.

Feb 8 '08 #2
On Feb 8, 10:35*am, "Jwe" <j...@mail.comw rote:
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. *The form is being displayed but the command
only returns when the form is closed. *I want the command line to
return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. *The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and display
a message. *This is working correctly.

If the correct number of arguments is supplied it should display
the command help. *This is working correctly.

In Project - Properties, the Output type is 'Windows Application'
and Startup object is 'Sub Main'.

Sub Main is basically:

* * * * arguments = Environment.Get CommandLineArgs ()

* * * * If arguments.Lengt h = 1 Then
* * * * * * 'No command line arguments so display the Windows
form
* * * * * * Dim frmMain As New frmWindows_Form
* * * * * * Application.Run (frmMain)

* * * * ElseIf arguments.Lengt h <3 Then
* * * * * * 'Required arguments not supplied, so display the help
* * * * * * Output_Command_ Help()

* * * * Else
* * * * * * 'Run command <--- WHATDOES THIS DO?

Any help much appreciated. *Thanks.
See note 4 lines up.
Feb 8 '08 #3
WinWord.exe, for example, can be started as a command line. I believe all
you would need to do in this case is to create a winforms application. If
the user starts it from a command line it should behave as you expect. Just
include your logic for the argument checks and write to Console.out.

"Jwe" wrote:
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line to
return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and display
a message. This is working correctly.

If the correct number of arguments is supplied it should display
the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows Application'
and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.
Feb 8 '08 #4
Jwe
Hi, thanks for your reply, however I'm not trying to run any
external program like Winword in the way you describe. This is a
single .exe generated by a single VB.Net project. The project
was started as a Windows Application (to get the Form in the
project) and then changed to a console app.

"Family Tree Mike" <Fa************ @discussions.mi crosoft.com>
wrote in message
news:81******** *************** ***********@mic rosoft.com...
WinWord.exe, for example, can be started as a command line. I
believe all
you would need to do in this case is to create a winforms
application. If
the user starts it from a command line it should behave as you
expect. Just
include your logic for the argument checks and write to
Console.out.

"Jwe" wrote:
>Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line
to
return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe ) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and
display
a message. This is working correctly.

If the correct number of arguments is supplied it should
display
the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows
Application'
and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the
help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.

Feb 8 '08 #5
Jwe
If I change the project to a Console Application, the behaviour
is different:

1. Run TheProgram.exe from a command prompt with no arguments:
the Windows form is displayed and the command prompt returns
immediately. This works as expected.

2. Run TheProgram.exe by double-clicking it in Windows Explorer:
the Windows form is display and no console window is opened.
This works as expected.

BUT:

3. Run TheProgram.exe from a command prompt with correct number
of arguments: runs as expected, but does not display the expected
message.

4. Run TheProgram.exe from a command prompt with incorrect number
of arguments: does not display the command help.

Thanks for any tips etc.

"Jwe" <jw*@mail.comwr ote in message
news:ce******** *************** *******@pipex.n et...
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line
to return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and
display a message. This is working correctly.

If the correct number of arguments is supplied it should
display the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows
Application' and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the
help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.

Feb 8 '08 #6
Sorry, I see how I confused you. I'm trying to say to switch back to a
winform app, and just lauch it from a command line. WinWord was just an
example. You would launch MyApplication.e xe if that is your built
executable. I thought however that System.IO.Conso le.WriteLine would still
work, but it doesn't seem to in my quick test. Sorry!
"Jwe" wrote:
Hi, thanks for your reply, however I'm not trying to run any
external program like Winword in the way you describe. This is a
single .exe generated by a single VB.Net project. The project
was started as a Windows Application (to get the Form in the
project) and then changed to a console app.

"Family Tree Mike" <Fa************ @discussions.mi crosoft.com>
wrote in message
news:81******** *************** ***********@mic rosoft.com...
WinWord.exe, for example, can be started as a command line. I
believe all
you would need to do in this case is to create a winforms
application. If
the user starts it from a command line it should behave as you
expect. Just
include your logic for the argument checks and write to
Console.out.

"Jwe" wrote:
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line
to
return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and
display
a message. This is working correctly.

If the correct number of arguments is supplied it should
display
the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows
Application'
and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the
help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.


Feb 8 '08 #7
Jwe

"Jwe" <jw*@mail.comwr ote in message
news:ce******** *************** *******@pipex.n et...
Hi,

I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.

When run from command line with no arguments it should display
the Windows form. The form is being displayed but the command
only returns when the form is closed. I want the command line
to return immediately, leaving the form displayed.

When run from Windows Explorer (by double-clicking on
TheProgram.exe) it should display the Windows form only. The
form is being displayed but a console window is also being
displayed.

When run from the command line with the correct number of
arguments it should operate on the supplied arguments and
display a message. This is working correctly.

If the correct number of arguments is supplied it should
display the command help. This is working correctly.

In Project - Properties, the Output type is 'Windows
Application' and Startup object is 'Sub Main'.

Sub Main is basically:

arguments = Environment.Get CommandLineArgs ()

If arguments.Lengt h = 1 Then
'No command line arguments so display the Windows
form
Dim frmMain As New frmWindows_Form
Application.Run (frmMain)

ElseIf arguments.Lengt h <3 Then
'Required arguments not supplied, so display the
help
Output_Command_ Help()

Else
'Run command
Any help much appreciated. Thanks.
http://forums.microsoft.com/MSDN/Sho...83493&SiteID=1
has a solution to the problem (incorporated in the code below)
which works for Visual Studio 2005 (Visual Basic 2005 Express,
Framework 2.0), but not for Visual Studio .NET 2003 (VB 2003
..NET, Framework 1.1).

Here's how to reproduce the problem using either Visual Basic
..NET 2003 or Visual Basic 2005:

Start a new Windows Application project - WindowsApplicat ion1.
This gives Form1.vb.
Add a Module to the project - Module1.vb
Replace the empty Module1 code with the following code:

Imports System.Environm ent

Module Module1

Declare Function AttachConsole Lib "kernel32" (ByVal
dwProcessId As Int32) As Boolean
Declare Function FreeConsole Lib "kernel32.d ll" () As Boolean

Sub Main()
Dim args As String() = GetCommandLineA rgs()
If args.Length = 1 Then
'No arguments so show windows form
Dim frmMain As New Form1
Application.Run (frmMain)
Else
AttachConsole(-1)
Console.WriteLi ne("Arguments supplied")
FreeConsole()
End If
End Sub

End Module
For VB 2003, in Project - Properties, leave Output type as
Windows Application and change Startup object to Sub Main.
For VB 2005, in Project - Properties, untick Enable application
framework, leave Output type as Windows Application and change
Startup object to Sub Main.

Build the project, then open a command prompt and run
WindowsApplicat ion1.exe from it as follows:

1. With no arguments. The form is displayed and the command
prompt returns immediately, allowing other commands to be
entered. Required behaviour.

2. With any number of arguments. The 'Arguments supplied' is
displayed for the VB 2005 application, but not for VB 2003.

3. Run it from Windows Explorer. The form is displayed and a
separate console window is not opened. Required behaviour.

So case 2 isn't working as required for VB 2003.

The AttachConsole and FreeConsole functions described in the link
above make case 2 work for VB 2005.

For the VB 2003 application, it fixes case 2 for a Debug build,
but has no effect for a Release build, which is exactly the same
findings as
http://groups.google.co.uk/group/mic...1643af7419e141

I'm interested in why it doesn't work for the VB 2003 Release
build, and any ideas for alternative fixes.

cheers,
Feb 11 '08 #8

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

Similar topics

7
6035
by: Ken Innes | last post by:
I am trying to write a little program that can be run as a Windows program or as a command line program. I'm really not sure the best way to do this, so what I came up with so far was to check for command line parameters (code shown below). This works, except that printf()'s don't display anything. Is there a better way to do this? WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int pszCmdLine) { if(ParamStr(5)!="") { main1(); //command...
7
4734
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the following for the command-line arguments: java -jar sforcedataloader.jar -Dsalesforce.config.dir=CONFIG_DIRECTORY They also give an example:
5
3222
by: randyelliott | last post by:
Good Day, I have a MS Access (Access 2000 now upgraded to 2003) database that tracks customer information. One function of this database is to create an encrypted license file for our software, which is then emailed out to the customer. The encryption string is based on information in the database and can only be generated by executing a DOS command. This is done from within the database by clicking a button on a form that triggers a...
5
2185
by: Jarod | last post by:
Hey I have already written a program that has a user interface, but I would like to add some command line interface too. So if the user run it like: program.exe paramater1 The program do something, but If not, the program normally run with windows interface. I tried Sub Main(args ... ) but I don't know how to connect it together. Jarod
14
4971
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons for things like delete, save, edit, cancel buttons - in the footer, or on the form detail section? 2. If in the footer, how do you add them to the tab order?
3
4054
by: Rico | last post by:
Hello, I'm new to VB.net and I have an application that I would like to open up in one of two different modes depending on a command line switch. The code will run as a scheduled task in Windows every fifteen minutes. I'd like to supply a command line switch (like "C:\Program Files\My Program\MyProg.exe /Auto") so the program will run without displaying the user interface. BUT, I'd like to show the interface if the command line...
0
2508
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
13
4508
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
51
4142
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under Command Prompt or Browser or some other application? Ojas.
0
8852
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9227
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
9145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5992
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
4497
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...
1
3206
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
2590
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2143
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.