Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is perhaps the one of the most unusual request for help that I can imagine, and I hope with bated breath you are able to help.

I am currently using Visual Studio 2013 Express edition, and using C#.

I am developing a program that can run installers loaded into a combobox. This makes it a lot tidier than having a lot of buttons for individual installers. Also this gives a distributor to have installers he wishes to distribute, and use this program to run them.

So far I've succeeded in getting the installers to load into their respective combo boxes, and have no issues here, but the problem is getting a loaded installer to execute (run) from the combo.

The code I used to try to get the installers to run is:

C#
Using System.Diagnostics;

private void cmbBibles_SelectedIndexChanged(object sender, EventArgs e)
{
    Process prcBibles=new Process();

    prcBibles.StartInfo=new ProcessStartInfo(cmbBibles.SelectedItem);
    prcBibles.StartInfo.UseShellExecute=true;
    prcBibles.Start();
}


The above code is a solution I found on StackOverflow, and in VS help. But when running the program I get a heap of errors.

I hope you can help with some really good solutions to get this running.

Kind Regards,
Stephen.
Posted
Updated 22-Apr-15 20:01pm
v2
Comments
ChrisCreateBoss 22-Apr-15 19:47pm    
Did you try just with "Process.Start(cmbBibles.SelectedItem);" ?
Sergey Alexandrovich Kryukov 22-Apr-15 19:51pm    
Amazing, isn't it?
Stephen8601 22-Apr-15 20:28pm    
Hi Chris,
I did, and it really hated it, of which this message popped up and after entering the code:

"The best overload method match for 'System.Diagnostics.ProcessStartInfo)' has some invalid arguments."

Here are some other things I've tried, and of which has failed.

prcBibles.StartInfo=new ProcessStartInfo("cmbBibles.SelectedItem");

prcBibles.StartInfo=new ProcessStartInfo(*.exe);
prcBibles.StartInfo=new ProcessStartInfo("*.exe");
prcBibles.StartInfo=new ProcessStartInfo(cmbBibles.SelectedItem. "*.exe");

And just a straight out System.Diagnostics.Process.Start which included all of the above, and failed.

So, with that, I simply cannot find an answer at the moment.

I also tried:

Private void cmbBibles_SelectionChangeCommitted(object sender, EventArgs e) using the same methods as before, and had no joy there.

So, at the moment I am really at a loss of what to do and where to go ahead.

Kind Regards,
Stephen

Sergey Alexandrovich Kryukov 22-Apr-15 23:18pm    
Of course, it should fail! How could you even come to the idea to write all that? ProcessStartInfo accepts file name, a string. I don't think you should even do any UI programming, processes, anything. You have no clue on the basics. So, you first need to learn the basics of programming, which is the best to do with simplest console-only applications.
—SA
Stephen8601 23-Apr-15 15:58pm    
Hi Sergey,
I've never tried to get an app to run from a combobox before, and therefore this is new ground for me. I know one can open database and document type files from a dropdown combobox, as this is something I do quite regularly in the Bible program I use.

Having said that, I work with what I have, and I try to find solutions, and with that, I also ask for help to find a solution if I what I currently know doesn't work. We are all on a journey of which we can learn from one another, and sometimes the solutions comes from the most odd and unusual places, and even from people who aren't programmers, of which has happened to me. Its all part of that journey.

Kind Regards,
Stephen

I tried using Process.Start and it seems to be working fine.

C#
using System.Diagnostics; 
//...
string myEXE = cmbBibles.SelectedItem.ToString();
Process.Start(myEXE);


But the comboBox must have the full path of your executable file to run.
You can show just the names of the executable files by: Creating a List<string></string>, adding the full paths to it, and use Path.GetFileNameWithoutExtension(); to show only names in the comboBox.

Hope this helps - CCB
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900