Create executable in memory (vb.net c#)

  • Thread starter Thread starter Lusamine
  • Start date Start date
L

Lusamine

Guest
Hi friends, I need to create an executable in memory and then allow it to be downloaded through a web service. I am going to embed a session token for this application, which is why I create it dynamically. My application will be in azure web service.

I've tried creating the file in a directory and if it generates the .exe file, but I need to do it in memory because I don't want to handle directories in Azure Services.

However, it does not perform any download. Anyone know what is missing or what I can do.

Sorry for my English, it's not my mother tongue.


Public Function DownloadFile() As System.IO.Stream Implements IServicioRemotoAutenticacionWebApi.DownloadFile
Dim codeProvider As New VBCodeProvider()
'Dim Output As String = "C:\Program Files\MyApp.exe"
Dim results As CompilerResults

Dim parameters As New CompilerParameters()


'Make sure we generate an EXE, not a DLL
parameters.GenerateExecutable = True
parameters.GenerateInMemory = True
parameters.CompilerOptions = ("/target:winexe") & " " & "/win32icon:" & """" & "SSICONO.ico" & """"

results = codeProvider.CompileAssemblyFromSource(parameters, " Imports System
Imports System.Diagnostics

Module Module1

Sub Main()

Dim CmdStr As String = ""CMD ARGUMENTS----""
Dim startInfo As New ProcessStartInfo(""CMD.EXE"")
'startInfo.WindowStyle = ProcessWindowStyle.Minimized
'startInfo.WindowStyle = ProcessWindowStyle.Hidden
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = False
startInfo.Arguments = CmdStr
Process.Start(startInfo)

End Sub

End Module")

If results.Errors.Count > 0 Then
'There were compiler errors
Dim CompErr As CompilerError
For Each CompErr In results.Errors
'MessageBox.Show(
' "Line number " & CompErr.Line &
' ", Error Number: " & CompErr.ErrorNumber &
' ", '" & CompErr.ErrorText & ";" &
' Environment.NewLine & Environment.NewLine)
Next
Else

'Successfull Compile
'MessageBox.Show("Your file is successfully generated!", "Success")
End If
Return results.CompiledAssembly.GetFile("Installer.exe")
End Function

Continue reading...
 
Back
Top