Thanks for the reply, I had already added the Exe file as a resource to
my Vb 2005 project but I need to extract that to a file, I am using the
code below:
C# (WORKING)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using System.Diagnostics;
namespace ExtractEmbeddedApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnExtract_Click(object sender, EventArgs e)
{
SaveFileDialog objSFD = new SaveFileDialog();
objSFD.InitialDirectory = "C:\\";
objSFD.Filter = "Executable (*.exe)|*.exe";
objSFD.Title = "Save embedded resource to...";
if (objSFD.ShowDialog() == DialogResult.OK)
{
Stream str =
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"ExtractEmbeddedApp.EmbeddedApp.exe");
byte[] fileBytes = new byte[str.Length];
str.Read(fileBytes, 0, fileBytes.Length);
str.Close();
str.Dispose();
FileStream fs = File.Create(objSFD.FileName);
fs.Write(fileBytes, 0, fileBytes.Length);
fs.Flush();
fs.Close();
fs.Dispose();
Process.Start(objSFD.FileName);
}
}
}
}
I want the same functionality in VB 2005
Tried below code without sucess , produces error (Error location marked
as <<== in code below):
System.NullReferenceException was unhandled Message="Object reference
not set to an instance of an object.":
Imports System
Imports System.Windows.Forms
Imports System.Reflection
Imports System.IO
Public Class frmMain
Private Sub btnSandboxie_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnSandboxie.Click
Dim m As IO.MemoryStream = LoadResource(Me.GetType.Namespace &
".MyApp1.exe")
SaveFile("c:\app1.exe", m)
End Sub
Private Function LoadResource(ByVal ResourceName As String) As
IO.MemoryStream
Dim ResourceStream As IO.Stream
ResourceStream =
Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(ResourceName)
If ResourceStream Is Nothing Then Return Nothing
Dim byts(CInt(ResourceStream.Length - 1)) As Byte
Dim Len As Integer = ResourceStream.Read(byts, 0,
CInt(ResourceStream.Length))
Dim MemStream As New IO.MemoryStream(byts, 0, Len)
Return MemStream
End Function
Private Sub SaveFile(ByVal FilePath As String, ByVal mstream As
System.IO.MemoryStream)
'save file to path specified
Dim FS As New FileStream(FilePath, IO.FileMode.Create,
IO.FileAccess.Write)
mstream.WriteTo(FS)
mstream.Flush()
FS.Close()
End Sub
End Class
i do not see the problem ,,,, there is a resource editor in the IDE in fact
a resource editor was already availlable in the ide since VB6 , i cannot
see the code on devcity as i do not have an account there .
regards
Michel