473,320 Members | 2,048 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,320 software developers and data experts.

command line arguments for a windows app

I want to write a windows app that accepts command line arguments. Does
anyone know if this can be done and if so, how to do it.
Aug 9 '05 #1
6 1548
Executing a console app:

ConsoleApp.exe -switch2

with the following class produces this output:

Switch two activated.

Class definition:

public class ConsoleApp
{
static void Main(string[] args)
{
if (args != null && args.Length > 0)
{
switch (args[0].Trim().ToLower())
{
case "-switch1":
Console.WriteLine("Switch one activated.");
break;
case "-switch2":
Console.WriteLine("Switch two activated.");
break;
default:
Console.WriteLine("No options selected");
break;
}
}
else
Console.WriteLine("No options selected");
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message news:9A**********************************@microsof t.com...
I want to write a windows app that accepts command line arguments. Does
anyone know if this can be done and if so, how to do it.

Aug 9 '05 #2
Will this work for a Windows Form App?

"Dave" wrote:
Executing a console app:

ConsoleApp.exe -switch2

with the following class produces this output:

Switch two activated.

Class definition:

public class ConsoleApp
{
static void Main(string[] args)
{
if (args != null && args.Length > 0)
{
switch (args[0].Trim().ToLower())
{
case "-switch1":
Console.WriteLine("Switch one activated.");
break;
case "-switch2":
Console.WriteLine("Switch two activated.");
break;
default:
Console.WriteLine("No options selected");
break;
}
}
else
Console.WriteLine("No options selected");
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message news:9A**********************************@microsof t.com...
I want to write a windows app that accepts command line arguments. Does
anyone know if this can be done and if so, how to do it.


Aug 9 '05 #3

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
Will this work for a Windows Form App?


It should.

Aug 10 '05 #4
I'm not sure I understand. Winform projects don't have a Main(). Then have
a Form_Load with already take a certain number of parameters. It doesn't
allow you to overload it with more parameters.
"Daniel O'Connell [C# MVP]" wrote:

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
Will this work for a Windows Form App?


It should.

Aug 10 '05 #5

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
I'm not sure I understand. Winform projects don't have a Main(). Then
have
a Form_Load with already take a certain number of parameters. It doesn't
allow you to overload it with more parameters.

They most assuredly do have a Main(). Most of the time it will be calling
Application.Run on your form.

Are you using VB by chance? If you are, you might have to ask someone who
knows the langauge better as I believe the default setup generates the Main
for you instead of having it in code explicitly.

"Daniel O'Connell [C# MVP]" wrote:

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
> Will this work for a Windows Form App?
>


It should.

Aug 11 '05 #6
OK. I got it working. Thanks for the help!!!

"Daniel O'Connell [C# MVP]" wrote:

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
I'm not sure I understand. Winform projects don't have a Main(). Then
have
a Form_Load with already take a certain number of parameters. It doesn't
allow you to overload it with more parameters.


They most assuredly do have a Main(). Most of the time it will be calling
Application.Run on your form.

Are you using VB by chance? If you are, you might have to ask someone who
knows the langauge better as I believe the default setup generates the Main
for you instead of having it in code explicitly.

"Daniel O'Connell [C# MVP]" wrote:

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
> Will this work for a Windows Form App?
>

It should.


Aug 11 '05 #7

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

Similar topics

2
by: Eric Ching | last post by:
Can I run pythonw with a script that takes command line arguments then launches a GUI? I try pythonw myscript.pyw -option arg (etc.) and nothing happens. Nothing, as in I am immediately returned...
2
by: SC | last post by:
I'm trying to hide command line arguments passed to a C++/Qt application compiled for Windows. Under Linux, I replaced argc in the main with empty spaces and it works, a 'ps -ef' does not show...
7
by: michael | last post by:
I have a question about Windows based python (2.4 and later). For example, if I make a script called test.py like so: import sys print sys.argv then run it: python test.py this is a test
7
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...
1
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
1
by: Rune Jacobsen | last post by:
Hi, I've been trying to figure this one out, but my experience just doesn't have what it takes... :| I am writing an application that reads an XML file and displays the contents in various...
40
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory...
6
by: 31337one | last post by:
Hello all, I was wondering if there is a C/C++ command line parser that works for linux AND windows. . Anyways, the ideal parser im looking for should be able to support multiple arguments...
4
by: Milan | last post by:
How do you pass in arguments from the command line to a .Net windows app. Senario: vb.net application should be able to execute from command prompt by passing login and password and should be...
7
by: Jwe | last post by:
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.