הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, January 24, 2018 1:02 PM
how Run an exe from resources in memorystream VB .NET
All replies (3)
Wednesday, January 24, 2018 1:36 PM ✅Answered
You are better off extracting the executable from resource and use Process.Run. Otherwise you would need something like the following which may or may not work dependent on the executable e.g. was it built in Visual Studio or not.
Imports System.IO
Public Class Demo
Public Shared Sub RunSearch(ByVal pPath As String, ByVal pText As String)
'Get the current assembly
Dim assembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
'Get the resource stream
Dim resourceStream As Stream = assembly.GetManifestResourceStream("path.executable name")
'Verify the internal exe exists
If resourceStream Is Nothing Then
Return
End If
'Read the raw bytes of the resource
Dim resourcesBuffer(CInt(resourceStream.Length) - 1) As Byte
resourceStream.Read(resourcesBuffer, 0, resourcesBuffer.Length)
resourceStream.Close()
'Load the bytes as an assembly
Dim exeAssembly As Reflection.Assembly = Reflection.Assembly.Load(resourcesBuffer)
Dim args() As String = {pPath, pText}
Dim parameters = New Object() {args}
Try
exeAssembly.EntryPoint.Invoke(Nothing, parameters)
Catch
'
' Handle exception
'
End Try
End Sub
End Class
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
Wednesday, January 24, 2018 1:29 PM
You cannot, a resource is an inclusion in an Exe.
This was in past a short while used to copy programs from others and wrapped that inside an own program and then sell it as an own program.
But it was only short that was possible.
Be aware that an .Net assembly is not direct a native executable. It only contains the .Net ILS code to be executed by the .Net framework runtime
Success Cor
Wednesday, January 24, 2018 2:37 PM
There is no point. First, the executable would need to be extracted and written as a file before it could be executed. Second, you would probably need to write it somewhere other than Program Files, which is protected by UAC. Third, some security software might consider it to be malware or a virus and block the operation.
Unless you are creating an installer application I would abandon this idea and simply include the executable as just another file in your application.
Paul ~~~~ Microsoft MVP (Visual Basic)