NDennisV
asked on
Cannot get StartInfo.Arguments to work
I cannot get StartInfo.Arguments to work.
It runs the program okay but does not see the arguments.
There are no spaces in the arguments.
You'll have to trust me that I need to that working directory.
I've searched the Internet for hours but cannot find a solution.
Thanks for any help.
Dennis
It runs the program okay but does not see the arguments.
System.Diagnostics.Process p = new Process();
p.StartInfo.WorkingDirectory = @"C:\Users\dennis\Documents\Visual Studio 2005\Projects\LocationMaintenance\LocationMaintenance\publish\";
p.StartInfo.FileName = @"LocationMaintenance.application";
p.StartInfo.Arguments = "dennis";
p.Start();
There are no spaces in the arguments.
You'll have to trust me that I need to that working directory.
I've searched the Internet for hours but cannot find a solution.
Thanks for any help.
Dennis
You don't actually supply a program that is to be run
ASKER
p.StartInfo.FileName = @"LocationMaintenance.appl ication";
Is the program to run. Am I missing something?
Like I said, the program runs but it does not see the arguments.
In the LocationMaintenance program I have:
Is the program to run. Am I missing something?
Like I said, the program runs but it does not see the arguments.
In the LocationMaintenance program I have:
string[] cmd = Environment.GetCommandLineArgs();
and these arguments work fine from a prompt.
There is nothing wrong with your implementation - took your code and did as follows
Works fine - so your problem is either in your application - or in the working folder (depends on how the application is interpreting your arguments - file - string etc).
System.Diagnostics.Process p = new Process();
p.StartInfo.WorkingDirectory = @"S:\data\";
p.StartInfo.FileName = @"C:\Windows\notepad.exe";
p.StartInfo.Arguments = "test.txt";
p.Start();
Works fine - so your problem is either in your application - or in the working folder (depends on how the application is interpreting your arguments - file - string etc).
You are aware that GetCommandLineArgs is different than Main(string[] args), I hope. The former includes the program name in index 0, and the first argument is actually in index 1; the latter does not have the program name as one of its entries, and the first argument is at index 0.
LocationMaintenance.applic ation - you say that is a program that runs by itself. (I must be getting old - I thought it required either exe or com as extension)
ASKER
I can get simple things like you posted to run too. I just cannot get this program to see the arguments.
I just tried
I just tried
static void Main(string[] args)
{
for (int i = 0; i < args.Length; ++i)
{
MessageBox.Show(args[i]);
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
and the program is not seeing the arguments.
@AndyAinscow
IIRC, you get an "application" extension if you use ClickOnce deployment : )
IIRC, you get an "application" extension if you use ClickOnce deployment : )
ASKER
Sorry Andy, I don't know what you mean?
I've tried LocationMaintenance.exe and it does not run.
I've tried LocationMaintenance.exe and it does not run.
As far as I know, the *.application file is not actually your program, but more like a manifest. You can open it up in a text editor and see that it is XML. Should I assume that the reason you are wanting to target the .application file is so that you can ensure any updates to the application are retrieved prior to the app running?
The explanation as to why the application does not see the arguments, so far as I can see, is because when you run the .application file, you are not actually running your program. You are running whichever application is registered to execute .application files (I do not know its name off the top of my head). For this reason, you are passing your arguments to that application, and not actually to the application you wish to target.
The explanation as to why the application does not see the arguments, so far as I can see, is because when you run the .application file, you are not actually running your program. You are running whichever application is registered to execute .application files (I do not know its name off the top of my head). For this reason, you are passing your arguments to that application, and not actually to the application you wish to target.
You sould use String[] instead of string[]
String[] arguments = Environment.GetCommandLine Args();
String[] arguments = Environment.GetCommandLine
Or use stringbuilder like that
System.Text.StringBuilder strbuilder= new System.Text.StringBuilder();
foreach (String arg in Environment.GetCommandLineArgs())
{
strbuilder.AppendLine(arg);
barcode = arg;
}
psnfo = strbuilder.ToString();
ASKER
In the publish folder there is only the application file and there is no exe file except setup.exe.
I just tried p.StartInfo.FileName = @"setup.exe"; and it also runs the program but still no arguments.
I just tried p.StartInfo.FileName = @"setup.exe"; and it also runs the program but still no arguments.
ASKER
Juat tried String[] instead of string[] and still not getting the arguments.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks kaufmed. It's lengthy and I'm burned out after working on this for 5 hours straight.
Looks like what I need and I think I now understand the problem with click once.
I'll get on it again after a few hours rest or tomorrow.
Thanks again.
Looks like what I need and I think I now understand the problem with click once.
I'll get on it again after a few hours rest or tomorrow.
Thanks again.
ASKER
I tried for many hours to get this to work and ended up writing a script file that does the same thing.
kaufmed's post was good and led me to understand that this is not always possible. Thanks.
kaufmed's post was good and led me to understand that this is not always possible. Thanks.