I'm developing a simple video player in Visual Basic 2010 Express. The program that plays the videos is in the compiled resources, and I'm trying to find a way to run it without having to place the program inside the bin folder.
-
Do you need to put it within the resources folder and cant you just run the programme from its directory by Importing `System.IO` and the using code like this `System.Diagnostics.Process.Start("notepad.exe")` This example launches notepad.exe and where notepad.exe is you simply replace it with your files name and directory. – Tom Jan 28 '14 at 19:32
-
But what im doing is this: i placed the program on the resources and want to run it from there... – GGG Jan 28 '14 at 19:37
-
Have you tried this? `Dim myFileName As String = "C:\test.exe" IO.File.WriteAllBytes(myFileName, My.Resources.testApp) If IO.File.Exists(myFileName) Then Process.Start(myFileName)` – Tom Jan 28 '14 at 19:42
-
why not just make mplayer.exe part of your install and copy it to the app folder? – Ňɏssa Pøngjǣrdenlarp Jan 28 '14 at 19:47
-
Idk, i think its better if i use a single exe – GGG Jan 28 '14 at 19:52
2 Answers
There is no easy way, via managed code to start a process from memory. The Process
class expects that the binary that you wish to run is a file on a disk. There are ways to pull it off using unmanaged API calls. For instance, here is a similar question with good answers for C++.
There are some answers to some other questions, like this one, where people recommend using an in-memory file system, like a RAM-disk to "trick" the Process
class into loading it from memory.
However, both of these strategies are ugly, brute-force methods. I would recommend that you strongly consider just writing the resource out to an executable file in the user's temp folder and then running it from there, before you go down one of these other roads.

- 1
- 1

- 43,358
- 8
- 68
- 105
-
But i dont have the source to the program, its already compiled, i didnt made it, what im trying to do is adding the program "x.exe" to the resources of my program "y.exe" and when my program gets compiled the "x.exe" will be compiled with it, and i want to run it when its already compiled with my program. – GGG Jan 28 '14 at 19:49
-
That's precisely the scenario I addressed in my answer. I'm not sure what it is in my answer that made you think that it involved source code for the other executable. Clearly I've confused you somewhere, but I'm not sure how. – Steven Doggart Jan 28 '14 at 19:52
-
Ok, i think i'll use Plutonix's suggestion as a temporary solution, until i learn more – GGG Jan 28 '14 at 19:53
-
As the unnamed user described in the comments to your question, and I also covered in my last paragraph, it would be easy to write the exe out to a temp file at run-time and then just launch that temp exe. However, I agree with Plutonix. If there is no good reason to embed it as a resource, I would also recommend just shipping it as a dependency to your application. Writing out embedded executables at runtime and launching is a security risk, so some users may not have permission to execute it anyway. – Steven Doggart Jan 28 '14 at 19:56
i think the best way is to start your program from the principal drive "c:\freevk.exe" as example using this syntax
Process.Start("C:\FreeVK.exe")
like this you don't need any super preveliges and everything is ok

- 20,585
- 22
- 95
- 108

- 1
- 1