14 Replies - 40162 Views - Last Post: 25 May 2012 - 09:29 AM Rate Topic: -----

#1 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 02:26 PM

Hi All DIC Heads,
I am currently working on a school project in VS2010. I have added a .exe file in the project folder and added it to the Project as a 'Existing Item'. In Project Properties -> Publish -> Application Files the .exe file is shown.

The .exe file runs quite nicely when I use the Process.Start("C:\NameOfMyApplicationFolder\MyProgram.exe") hard code path to the .exe file. However, I am faced with two(2) challenges that I need to overcome, and would appreciate any help with them. These are they:
1. If published on another machine the .exe file will not run as the hard code path to the .exe file will be different from that on my machine. Therefore I need a way to create a generic path to the .exe file. I have tried these [Process.Start("C:\|DataDirectory|\MyProgram.exe")] AND [Process.Start("Localhost\|DataDirectory|\MyProgram.exe")]; I got an error message that "The system cannot find the file specified".

2. I am putting the Process.Start("xxxxx.\MyProgram.exe") on a button click event. I also want to put the running of the .exe file between two(2) lines of code. The first line of code is basically asking "Do you wish to run the executable file" - YesNo. If 'Yes' is selected the .exe file is run. Here is the problem: When the .exe program is closed the second line of code is to be executed. I have gotten the .exe to run (using the hard code file path) when 'Yes' is selected, and the second line of code to execute if 'No' is selected, but I have not been successful in getting the second line of code to execute after closing the .exe program. I have tried this:
[If Process.Start("C:\NameOfMyApplicationFolder\MyProgram.exe").CloseMainWindow = True Then
Do line 2
End if]. nothing happens when I close the .exe program.

I know this is lengthy but I am trying to give as much detail as possible.

Any help will be appreciated. I would also appreciate clear instructions on where and how to apply the solution(s).

Kind regards,

rehtnapc

Is This A Good Question/Topic? 0
  • +

Replies To: How to run a .exe file from inside a VS2010 project

#2 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 323
  • Joined: 12-January 11

Re: How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 02:35 PM

I have never added an actual .exe to any of my projects, however, can't you just go toe the Resources page of the project properties and add the file to it? If you were able to do that, you would just be able to reference it using "My.Resources.xxxxx". Again, I'm not sure about this, but its worth a try if no one else has a suggestion.
Was This Post Helpful? 1
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 02:51 PM

There was a discussion about that here
Was This Post Helpful? 1
  • +
  • -

#4 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

Re: How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 02:52 PM

Psyguy
Thanks for your prompt response.

I just tried
Process.Start("My.Resources\MyProgram.exe")
and got an error message "The system cannot find the file specified". Any other suggestion?

Regards,

rehtnapc
Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2264
  • View blog
  • Posts: 9,469
  • Joined: 29-May 08

Re: How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 04:02 PM

You'll need to extract it to a Temporary Location or use LocalApplicationData

   Dim myLocalAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)


You use the method found on the follow DIC Thread
Was This Post Helpful? 1
  • +
  • -

#6 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

Re: How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 04:20 PM

Hi smohd,
I saw that thread and asked questions there, but it was recommended that I start my own thread, hence here we are.
The postings there deals with .msi files. Notwithstanding, I have tried to manipulate the codes but to no avail. I tired this
Process.Start(My.Computer.FileSystem.CurrentDirectory & "\MyProgram.exe")
and I no longer get the error message that "The system cannot find the file specified", instead I get a error message "The specified executable is not a valid application for this OS platform". As I said in my initial post, when I use the hard code path to the same .exe file it runs ok.

Regards,

rehtnapc
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2264
  • View blog
  • Posts: 9,469
  • Joined: 29-May 08

Re: How to run a .exe file from inside a VS2010 project

Posted 22 August 2011 - 04:46 PM

Reexamine the thread i linked to.
Was This Post Helpful? 1
  • +
  • -

#8 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

Re: How to run a .exe file from inside a VS2010 project

Posted 23 August 2011 - 04:16 PM

View PostAdamSpeight2008, on 22 August 2011 - 06:46 PM, said:

Reexamine the thread i linked to.


Hi AdamSpeight2008
Thanks for your input. Trying to understand what I am seeing in the link. Will let you know how it goes.

Can you shed any light on the second part of my original post; that of getting the application to run a second line of code only after the .exe program is closed?

Regards,

rehtnapc
Was This Post Helpful? 0
  • +
  • -

#9 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

Re: How to run a .exe file from inside a VS2010 project

Posted 23 August 2011 - 05:10 PM

I have followed the link and followed the instructions. The code works to save the file to disk. However, I am not trying to save the file to disk; I am trying to write a generic code for the path to the .exe file to run it. I also want the application to execute another line of code after the .exe program is closed.

Any other ideas?

Regards,

rehtnapc
Was This Post Helpful? 0
  • +
  • -

#10 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

Re: How to run a .exe file from inside a VS2010 project

Posted 02 September 2011 - 08:15 AM

Hi All DIC Heads,
I have finally discovered how to create a generic path to the .exe or other files included in my VB 2010 project, that I wish to execute. This may need some tweaking for your particular purpose, but it just may help. So for those who may find this helpful here goes.
1. Copy the required .exe or .xxx file into the project folder
2. Through the 'Solution Explorer' add the .exe or .xxx file to the project. One way of doing this is by Right clicking on the project name (In bold letters at the top of the Solution Explorer window) -> Add -> Existing Item and then navigate to the project folder, click on the file -> Add. The file should now appear in the 'Solution Explorer'
3. Highlight the file in the 'Solution Explorer'. Go to 'Properties', set 'Build Action' to 'Content' and 'Copy to Output Directory' to 'Copy always'.
4. Save all
5. Under your button click event or whatever event you are using to launch the .xxx file, use this code:
Process.Start(My.Computer.FileSystem.CurrentDirectory & "\File Name.exe")


Thanks to all who offered me advice while I was seeking help and I hope this will be helpful to someone.

Regards

rehtnapc
Was This Post Helpful? 0
  • +
  • -

#11 crob09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-April 12

Re: How to run a .exe file from inside a VS2010 project

Posted 28 April 2012 - 01:28 PM

View Postrehtnapc, on 02 September 2011 - 08:15 AM, said:

Hi All DIC Heads,
I have finally discovered how to create a generic path to the .exe or other files included in my VB 2010 project, that I wish to execute. This may need some tweaking for your particular purpose, but it just may help. So for those who may find this helpful here goes.
1. Copy the required .exe or .xxx file into the project folder
2. Through the 'Solution Explorer' add the .exe or .xxx file to the project. One way of doing this is by Right clicking on the project name (In bold letters at the top of the Solution Explorer window) -> Add -> Existing Item and then navigate to the project folder, click on the file -> Add. The file should now appear in the 'Solution Explorer'
3. Highlight the file in the 'Solution Explorer'. Go to 'Properties', set 'Build Action' to 'Content' and 'Copy to Output Directory' to 'Copy always'.
4. Save all
5. Under your button click event or whatever event you are using to launch the .xxx file, use this code:
Process.Start(My.Computer.FileSystem.CurrentDirectory & "\File Name.exe")


Thanks to all who offered me advice while I was seeking help and I hope this will be helpful to someone.

Regards

rehtnapc


Hi, I am trying to do this but for some reason the add option under the file tab only allows for certain file types. I don't fully understand where I am supposed to right click to find the Add option the way you suggested. Can you help me a little?
Thanks for your time and help so far, at least this gives something to go on. Also good on you for figuring it out!
I am using VB 2010
Was This Post Helpful? 0
  • +
  • -

#12 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: How to run a .exe file from inside a VS2010 project

Posted 28 April 2012 - 02:53 PM

If you want to show all of the files in a folder type *.* into the file name box and press Enter.
Was This Post Helpful? 0
  • +
  • -

#13 crob09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-April 12

Re: How to run a .exe file from inside a VS2010 project

Posted 28 April 2012 - 08:02 PM

View PostDimitriV, on 28 April 2012 - 02:53 PM, said:

If you want to show all of the files in a folder type *.* into the file name box and press Enter.


.
Thanks,
I am trying to save a file that has a couple of things I am calling with my build but can't figure out how, does anyone have any thoughts?
Was This Post Helpful? 0
  • +
  • -

#14 rehtnapc  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 06-February 11

Re: How to run a .exe file from inside a VS2010 project

Posted 25 May 2012 - 05:53 AM

View Postcrob09, on 28 April 2012 - 03:28 PM, said:

View Postrehtnapc, on 02 September 2011 - 08:15 AM, said:

Hi All DIC Heads,
I have finally discovered how to create a generic path to the .exe or other files included in my VB 2010 project, that I wish to execute. This may need some tweaking for your particular purpose, but it just may help. So for those who may find this helpful here goes.
1. Copy the required .exe or .xxx file into the project folder
2. Through the 'Solution Explorer' add the .exe or .xxx file to the project. One way of doing this is by Right clicking on the project name (In bold letters at the top of the Solution Explorer window) -> Add -> Existing Item and then navigate to the project folder, click on the file -> Add. The file should now appear in the 'Solution Explorer'
3. Highlight the file in the 'Solution Explorer'. Go to 'Properties', set 'Build Action' to 'Content' and 'Copy to Output Directory' to 'Copy always'.
4. Save all
5. Under your button click event or whatever event you are using to launch the .xxx file, use this code:
Process.Start(My.Computer.FileSystem.CurrentDirectory & "\File Name.exe")


Thanks to all who offered me advice while I was seeking help and I hope this will be helpful to someone.

Regards

rehtnapc


Hi, I am trying to do this but for some reason the add option under the file tab only allows for certain file types. I don't fully understand where I am supposed to right click to find the Add option the way you suggested. Can you help me a little?
Thanks for your time and help so far, at least this gives something to go on. Also good on you for figuring it out!
I am using VB 2010


Hi crob09,
I am sorry for just replying to your request - haven't checked the Threads in a long while.
Anyway, I hope it is not too late:

Do the following:
1. On the toolbar at the top of the Visual Studio (where it says: File | Edit | View | Project |etc.), click on 'View'. A drop down list will appear.
2. About the fifth item on the list (from the top) it say Solution Explorer Ctrl+Alt+L. Click on Solution Explorer. The Solution Explorer window will open on the right side of the screen.
3. At the top of the Solution Explorer window it will say Solution 'The Name of your project' (1 project). Below that in bold letters you will again see the name of your project.
4. Right click on the bold lettering. A menu will appear. About the fifth item on the menu it should say Add.
5. Mouse over the word 'Add' and a sub-menu will appear. The second item on that sub-menu should say Existing Item.

From there you can follow the remaining steps outlined in my earlier post.

I hope this is helpful, though late.

Regards,
Was This Post Helpful? 0
  • +
  • -

#15 crob09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-April 12

Re: How to run a .exe file from inside a VS2010 project

Posted 25 May 2012 - 09:29 AM

View Postrehtnapc, on 25 May 2012 - 05:53 AM, said:

View Postcrob09, on 28 April 2012 - 03:28 PM, said:

View Postrehtnapc, on 02 September 2011 - 08:15 AM, said:

Hi All DIC Heads,
I have finally discovered how to create a generic path to the .exe or other files included in my VB 2010 project, that I wish to execute. This may need some tweaking for your particular purpose, but it just may help. So for those who may find this helpful here goes.
1. Copy the required .exe or .xxx file into the project folder
2. Through the 'Solution Explorer' add the .exe or .xxx file to the project. One way of doing this is by Right clicking on the project name (In bold letters at the top of the Solution Explorer window) -> Add -> Existing Item and then navigate to the project folder, click on the file -> Add. The file should now appear in the 'Solution Explorer'
3. Highlight the file in the 'Solution Explorer'. Go to 'Properties', set 'Build Action' to 'Content' and 'Copy to Output Directory' to 'Copy always'.
4. Save all
5. Under your button click event or whatever event you are using to launch the .xxx file, use this code:
Process.Start(My.Computer.FileSystem.CurrentDirectory & "\File Name.exe")


Thanks to all who offered me advice while I was seeking help and I hope this will be helpful to someone.

Regards

rehtnapc


Hi, I am trying to do this but for some reason the add option under the file tab only allows for certain file types. I don't fully understand where I am supposed to right click to find the Add option the way you suggested. Can you help me a little?
Thanks for your time and help so far, at least this gives something to go on. Also good on you for figuring it out!
I am using VB 2010


Hi crob09,
I am sorry for just replying to your request - haven't checked the Threads in a long while.
Anyway, I hope it is not too late:

Do the following:
1. On the toolbar at the top of the Visual Studio (where it says: File | Edit | View | Project |etc.), click on 'View'. A drop down list will appear.
2. About the fifth item on the list (from the top) it say Solution Explorer Ctrl+Alt+L. Click on Solution Explorer. The Solution Explorer window will open on the right side of the screen.
3. At the top of the Solution Explorer window it will say Solution 'The Name of your project' (1 project). Below that in bold letters you will again see the name of your project.
4. Right click on the bold lettering. A menu will appear. About the fifth item on the menu it should say Add.
5. Mouse over the word 'Add' and a sub-menu will appear. The second item on that sub-menu should say Existing Item.

From there you can follow the remaining steps outlined in my earlier post.

I hope this is helpful, though late.

Regards,

Not to late at all! Thank you for getting back to me and for your help, I will try it and let you know how it works out.
:bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1