I am trying to make a program that will will make it easier for me to access some of my smaller frequently used program. I am new to Visual Basic and just discovered how to embed a .exe file into the project. I just dont know how to open it now. Basically there is a button and when it is clicked it needs to open up a .exe file, lets just call it 1.exe. I have looked around everywhere on how to do this and all I found was some resourcemanager commands but I have not been able to get them to work can someone please help me and post some sample code because like I said I just started using visual basic.
Thanks

How do you open an embedded resource?
jtweku
Thanks
Ajay Tandon
In the following example, I have temporarily borrowed
Microsoft's calc.exe program and added it as an embedded
resource. I then write it out as a new file named 'zzzz.exe' to
show that I am not running the original 'calc.exe'.
(Of course I could not redistribute this without MS's permission.
You can alway launch a MS program that should exist, but you
cannot legally embed it and redistribute it like this.)
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim data() As Byte = My.Resources.calc
Dim file As New System.IO.FileStream("zzzz.exe", IO.FileMode.Create)
file.Write(data, 0, data.Length)
file.Close()
' Run the Calc program named zzzz
Dim p As New Process
p.StartInfo.FileName = "zzzz.exe "
p.Start()
End Sub
Yaroslav
johnny_no1_boy
Okay. That tells me a little more. You can use My.Resources.anydvd to access the bytes of the executable. You will need to save these bytes off as a file using a FileStream and then run the executable using the Process class.
benconnol1y
csgary
Michael Eng
That went so far above my head I couldnt even see it, lol.. I am just starting to get into visual basic and I know nothing about filestreams and process classes, I have tried to look them up but MSDN's explanations dont really help me, is there anyway you could please give me a quick short code example of how I would do that. THe only reas I really need to learn how to do this is because I plan on making alot more programs like this, (if I can ever get this one working).. Thanks,
Garrett Serack
This is what it would look like.
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Some_Stream As System.IO.Stream
Some_Stream = GetManifestResourceStream("EXE1")
End Sub
Public Overridable Function GetManifestResourceStream(ByVal name As String) As System.IO.Stream
Return Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(name)
End Function
End Class
Dustin.
WGParrish
Thanks alot dustin for the help, I understand it alot more know but still cannot get it to work, below is the code for the form. I included it as a resource in Slysoft.resx and I set its Build Action to Embedded Resource. The name of the file is anydvd.exe I get no errors when building it but when I click on the button nothing happens. Do you see any problems with the code below (I also took you the .exe and it still didnt work)
Thanks a bunch.
Imports System.IO
Imports System.Security.Cryptography
Public
Class SlysoftPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Overridable Function GetManifestResourceStream(ByVal name As String) As System.IO.Stream
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickReturn Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(name)
End Function
Dim anydvd As System.IO.Stream
anydvd = GetManifestResourceStream("anydvd.exe")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim clonedvd As System.IO.Stream
clonedvd= GetManifestResourceStream("clonedvd.exe")
End Sub
End Class
stlaural
It is quite hard to determine the correct name for a resource as it is based on the default namespace of the project and the folder the resource is contained under the project.
An easy way to determine the name of your resource is use a tool such as the free .NET Reflector. Open your application with it and look under the Resources node to see the name of your resource.
mehrit
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.IO;
void useEmbeddedExecutable()
{
Assembly ens = Assembly.GetExecutingAssembly();
//read file to byte array
int) s.Length);Stream s = ens.GetManifestResourceStream("anyproject.anyfile.exe");
byte[] bytes = new byte[s.Length];
s.Read(bytes, 0, (
s.Close();
//copy file
FileStream sw = File.Create(@"C:\anyproject\anyfile.exe");
sw.Write(bytes, 0, (int) bytes.Length);
sw.Close();
//launch executable
Process myProcess = new Process();
myProcess.StartInfo.FileName = "C:\anyproject\anyfile.exe";
myProcess.Start();
}
Now make it VB...
Cheers
Mentoche.
timleong
Here is how you can write simplified VB 2005 code. My solution is very similar to the approaches above. I simplify things by using the Project Designer Resources tab and the My.Computer.FileSystem namespace.
Steps:
- open the Project Designer by double-clicking on the My Project node in Solution Explorer (this is where you design the entire application)
- click on the Resources tab (this is where you add and edit embedded resources)
- drag and drop your program.exe file from any windows explorer window into the Resources window (I used the Mshearts.exe file)
- add this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.runApp(My.Resources.mshearts, "mshearts.exe")
End Sub
''' <summary>
''' runs an embedded application resource
''' </summary>
''' <param name="appBinaryData">application binary data</param>
''' <param name="appName">name of the application with extension, e.g. "mshearts.exe"</param>
''' <remarks>pass in binary data from My.Resources</remarks>
Public Sub runApp(ByVal appBinaryData As Byte(), ByVal appName As String)
'TODO: add code validate inputs as appropriate
'choose a file path to save to in the current program folder
Dim appPath As String = My.Application.Info.DirectoryPath & "\" & appName
'save the embedded app binary to the file path
My.Computer.FileSystem.WriteAllBytes(appPath, My.Resources.mshearts, False)
'start the process
'warning -- validate users should be allowed to execute the value of appPath!
Process.Start(appPath)
End Sub
Enjoy,
Paul Yuknewicz
SatheeshLives
Timothy.J.Cooper
Simply add the executable to your project, right-click it in Solution Explorer and select Properties. Then in the Properties windows, change Build Action to EmbeddedResource.