473,320 Members | 1,766 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

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 able to execute
process form (with his parameter)
User should not be able to see GUI

Milan

Dec 4 '06 #1
4 4136
Hello Milan,

string[] args signature of the Main method to get access to the command line
param.
or maybe i don't undestand the problem

MHow do you pass in arguments from the command line to a .Net windows
Mapp.
M>
MSenario: vb.net application should be able to execute from command
Mprompt by passing login and password and should be able to execute
Mprocess form (with his parameter)
MUser should not be able to see GUI
MMilan
M>
---
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 4 '06 #2
Try Environment.CommandLine
Dec 4 '06 #3
The entry point for a Windows application in the .Net Framework is a static
method called "Main" (not sure what the VB.Net implementation is, but it is
similar). The Main method can take a list of arguments, which are
command-line arguments. So, for example, here is some code for a C# (sorry)
program I wrote that takes command-line arguments:

static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
string docToOpen = null, saveFilePath = null;
bool refresh = false;
string arg;
Utilities.SetEventLogSourceAndName(
Properties.Settings.Default.EventLogSource,
Properties.Settings.Default.EventLogName);
if (args.Length 0)
{
// find the file path to open, if it exists
for (int i = 0; i < args.Length; i++)
{
arg = args[i].Trim();
if (arg.StartsWith("/"))
{
if (arg.StartsWith("/sfp:",
StringComparison.CurrentCultureIgnoreCase) ||
arg.StartsWith("/saveFilePath:",
StringComparison.CurrentCultureIgnoreCase))
saveFilePath = arg.Substring(arg.IndexOf(':') + 1);
else if (arg.StartsWith("/refresh")) refresh = true;
}
else if (File.Exists(arg)) docToOpen = arg;
}
if (docToOpen != null && saveFilePath == null)
saveFilePath = Path.GetDirectoryName(docToOpen);
Application.UseWaitCursor = true;
if (docToOpen != null || saveFilePath != null)
Application.Run(new PrintManager(docToOpen, saveFilePath,
refresh));
else
Application.Run(new PrintManager());
}
else
Application.Run(new PrintManager());
}

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"Milan" <mi********@googlemail.comwrote in message
news:11*********************@l12g2000cwl.googlegro ups.com...
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 able to execute
process form (with his parameter)
User should not be able to see GUI

Milan

Dec 5 '06 #4
Thanks a ton

Kevin Spencer wrote:
The entry point for a Windows application in the .Net Framework is a static
method called "Main" (not sure what the VB.Net implementation is, but it is
similar). The Main method can take a list of arguments, which are
command-line arguments. So, for example, here is some code for a C# (sorry)
program I wrote that takes command-line arguments:

static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
string docToOpen = null, saveFilePath = null;
bool refresh = false;
string arg;
Utilities.SetEventLogSourceAndName(
Properties.Settings.Default.EventLogSource,
Properties.Settings.Default.EventLogName);
if (args.Length 0)
{
// find the file path to open, if it exists
for (int i = 0; i < args.Length; i++)
{
arg = args[i].Trim();
if (arg.StartsWith("/"))
{
if (arg.StartsWith("/sfp:",
StringComparison.CurrentCultureIgnoreCase) ||
arg.StartsWith("/saveFilePath:",
StringComparison.CurrentCultureIgnoreCase))
saveFilePath = arg.Substring(arg.IndexOf(':') + 1);
else if (arg.StartsWith("/refresh")) refresh = true;
}
else if (File.Exists(arg)) docToOpen = arg;
}
if (docToOpen != null && saveFilePath == null)
saveFilePath = Path.GetDirectoryName(docToOpen);
Application.UseWaitCursor = true;
if (docToOpen != null || saveFilePath != null)
Application.Run(new PrintManager(docToOpen, saveFilePath,
refresh));
else
Application.Run(new PrintManager());
}
else
Application.Run(new PrintManager());
}

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"Milan" <mi********@googlemail.comwrote in message
news:11*********************@l12g2000cwl.googlegro ups.com...
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 able to execute
process form (with his parameter)
User should not be able to see GUI

Milan
Dec 12 '06 #5

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

Similar topics

6
by: Hari | last post by:
can i have command line arguments in VS.NET applicatio? if yes how? Can i have some code snippets of the above functionality? I know we can acjieve this in console application form command...
6
by: Jon Hewer | last post by:
hi i am writing a little script and currently implementing command line arguments following the guide by mark pilgrim from dive into python; ...
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...
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
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...
4
by: Roland | last post by:
Hi, I am developing a C++ project and want to pass some command line arguments in VS .NET 2003. I am in debug mode, the configuration is set to Debug and I entered my argument list in Project ->...
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...
2
by: Milan | last post by:
Hi, Please guide me how to set command line argument and how to retrive command line argument. Senario: vb.net application should be able to execute from command prompt by passing login and...
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:
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...
1
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: 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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.