Command Line Arguments

M

Milan

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
 
M

Michael Nemtsev

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

M> How do you pass in arguments from the command line to a .Net windows
M> app.
M>
M> Senario: vb.net application should be able to execute from command
M> prompt by passing login and password and should be able to execute
M> process form (with his parameter)
M> User should not be able to see GUI
M> Milan
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 Nietzsch
 
K

Kevin Spencer

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(false);
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.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.
 
M

Milan

Thanks a ton

Kevin said:
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(false);
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.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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top