EXE that creates EXE

Posts 16–17 of 17 · Page 2 of 2
Quote Originally Posted by aLcohoL_95 View Post


im not talking about its easy or hard
im talking about is it possiblie or impossible

so its %100 possible
but not easy as u said
and i think its easier then compiling code with mscvr.dll :P
I know, I know. I was just saying ;[
Code:
Imports System.CodeDom.Compiler

x2 Textbox (Textbox1.text & Textbox2.text)
x1 Button (Button1)

Code:
Dim CompilePath As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim FileSave As New SaveFileDialog 'Declares a save file dialog so the user can specify where to save the compiled file.
Call CompileCode()
  With FileSave
    .InitialDirectory = Application.StartupPath 'Sets initial directory to the startup path of the application.

    .FileName = "*.exe"
    .DefaultExt = ".exe|*.exe"
  End With

  If FileSave.ShowDialog = Windows.Forms.DialogResult.OK Then
    CompilePath = FileSave.FileName
  Else : Exit Sub 'If the user hits cancel/'X', we exit the sub.
  End If
    End Sub

Sub CompileCode()
  Dim TheCode As String = TextBox1.Text 'Stores the written code in the 'TheCode' variable.
  CreateEXE(CompilePath, TheCode) 'Calls the function to Compile the code, with "CompilePath" as the location for the code to be compiled to, and "TheCode" as the code to be compiled.
    End Sub
Sub CreateEXE(ByVal SaveLocation As String, ByVal Code As String)
  On Error Resume Next 'To Avoid exceptions being thrown.

  Dim Settings As New CompilerParameters() 'To store the settings of our compiler in.
  Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler 'Declaring our compiler.

  With Settings 'Setting some Settings for the compiler.
    .GenerateExecutable = True
    .OutputAssembly = SaveLocation 'Sets save location to the place the user inputed in the FileSave.sfd
    .CompilerOptions = "/target:winexe" 'Tells the compiler to compile the code as a winexe file.
    .ReferencedAssemblies.Add("System.dll") 'Imports System
  End With

  Code = Code.Replace("[*message*]", TextBox2.Text) 'Replaces the place holder for the message box's message with the message that was entered in textbox2.text
  Compiler.CompileAssemblyFromSource(Settings, Code) 'Compiles the code with all the settings stored in the "Settings" string.
    End Sub
Posts 16–17 of 17 · Page 2 of 2

Post a Reply

Tags for this Thread

None

Talk with us