exe erstellen mit text

  • VB.NET

Es gibt 43 Antworten in diesem Thema. Der letzte Beitrag () ist von Hunter110.

    exe erstellen mit text

    Hey,

    Ich wollte in ein Programm bzw eine textbox zb eingeben: Hallo das wird dann in eine exe compilliert und wenn ich diese ausführe kommt ne msgbox mit Hallo. Hatt jemand ein plan wie ich eine exe compiliere?

    Thema übersteigt die Grundlagen
    * Thema verschoben *

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „der_Kurt“ ()

    ja aber hab kp was ich daran änden soll kriege 3 errors rein:

    Fehler 1 Für den Parameter "code" von "Private Function CompileCode(code As String, tmpfile As String, outpath As String) As Boolean" wurde kein Argument angegeben. C:\Users\Max\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 4 9


    wo füg ich denn code überhaupt ein?
    machs so:

    VB.NET-Quellcode

    1. Private Function CompileCode(ByVal code As String, ByVal tmpfile As String, ByVal outpath As String) As Boolean
    2. IO.File.WriteAllText(tmpfile, code)
    3. If IO.File.Exists(outpath) Then IO.File.Delete(outpath)
    4. Dim p As New Process With {.StartInfo = New ProcessStartInfo With {.Arguments = " /t:exe """ & tmpfile & """", .WindowStyle = ProcessWindowStyle.Hidden, .FileName = IO.Path.Combine(New IO.FileInfo(Application.ExecutablePath).Directory.Root.FullName, "WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe")}}
    5. p.Start()
    6. p.WaitForExit()
    7. Return IO.File.Exists(outpath)
    8. End Function

    und dann rufst du es so auf:

    VB.NET-Quellcode

    1. CompileCode(richtextbox1.text, "C:\Users\deinname\Desktop\exe.vb", "C:\Users\deinname\Desktop\exe.exe")


    lg Gugi
    ich habe es jetzt so erweitert leider kommt kein fehler und es passiert nichts:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim code As String
    3. Dim pfad As String = Application.StartupPath + "\code.exe"
    4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5. End Sub
    6. Private Function CompileCode(ByVal code As String, ByVal tmpfile As String, ByVal outpath As String) As Boolean
    7. IO.File.WriteAllText(tmpfile, code)
    8. If IO.File.Exists(outpath) Then IO.File.Delete(outpath)
    9. Dim p As New Process With {.StartInfo = New ProcessStartInfo With {.Arguments = " /t:exe """ & tmpfile & """", .WindowStyle = ProcessWindowStyle.Hidden, .FileName = IO.Path.Combine(New IO.FileInfo(Application.ExecutablePath).Directory.Root.FullName, "WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe")}}
    10. p.Start()
    11. p.WaitForExit()
    12. Return IO.File.Exists(outpath)
    13. End Function
    14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    15. code = textbox1.text
    16. CompileCode(code, pfad, pfad)
    17. End Sub
    18. End Class
    es passiert immer noch nichts....

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim code As String
    3. Dim pfad As String = Application.StartupPath + "\code.vb"
    4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5. End Sub
    6. Private Function CompileCode(ByVal code As String, ByVal tmpfile As String, ByVal outpath As String) As Boolean
    7. IO.File.WriteAllText(tmpfile, code)
    8. If IO.File.Exists(outpath) Then IO.File.Delete(outpath)
    9. Dim p As New Process With {.StartInfo = New ProcessStartInfo With {.Arguments = " /t:exe """ & tmpfile & """", .WindowStyle = ProcessWindowStyle.Hidden, .FileName = IO.Path.Combine(New IO.FileInfo(Application.ExecutablePath).Directory.Root.FullName, "WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe")}}
    10. p.Start()
    11. p.WaitForExit()
    12. Return IO.File.Exists(outpath)
    13. End Function
    14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    15. code = TextBox1.Text
    16. CompileCode(code, pfad, pfad)
    17. End Sub
    18. End Class
    Es gibt noch eine andere Möglichkeit bei der du glaube ich nicht von VS abhängig bist:
    Bin mir nicht mehr ganz sicher wo der Code her ist, kommt aber glaube ich von vbarchiv.
    Hab nur ein paar Anpassungen gemacht, sollte aber funktionieren.

    VB.NET-Quellcode

    1. ''' <summary>
    2. ''' Kompilliert einen VB-Code
    3. ''' </summary>
    4. ''' <param name="CodeS">Enthält den zu kompilierenden Code</param>
    5. ''' <param name="NameS">Enthält den Namen des Programmes</param>
    6. ''' <returns>True: Erfolgreich; False: Fehlgeschlagen</returns>
    7. ''' <remarks></remarks>
    8. Function CodeCreator(ByVal CodeS As String, ByVal NameS As String) As Boolean
    9. Dim Results As CompilerResults
    10. Dim Fehlermeldung As String = ""
    11. Dim Parameters As CompilerParameters
    12. Dim Provider As Microsoft.VisualBasic.VBCodeProvider
    13. Dim Errors As CodeDom.Compiler.CompilerErrorCollection
    14. Parameters = New CompilerParameters
    15. With Parameters
    16. .OutputAssembly = NameS
    17. .GenerateExecutable = True
    18. .MainClass = "Main"
    19. End With
    20. Provider = New Microsoft.VisualBasic.VBCodeProvider
    21. Results = Provider.CompileAssemblyFromSource(parameters, CodeS)
    22. Errors = Results.Errors
    23. For Each Er In Errors
    24. If Er.ToString IsNot Nothing Then
    25. Fehlermeldung &= Er.ToString & Environment.NewLine & "-------" & Environment.NewLine
    26. End If
    27. Next
    28. If Fehlermeldung = "" Then
    29. Return True
    30. Else
    31. MsgBox(Fehlermeldung)
    32. Return False
    33. End If
    34. End Function


    Mfg
    Firestorm
    @Jackbauer
    du musst es so machen:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim code As String
    3. Dim pfad As String = Application.StartupPath & "\"
    4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5. End Sub
    6. Private Function CompileCode(ByVal code As String, ByVal tmpfile As String, ByVal outpath As String) As Boolean
    7. IO.File.WriteAllText(tmpfile, code)
    8. If IO.File.Exists(outpath) Then IO.File.Delete(outpath)
    9. Dim p As New Process With {.StartInfo = New ProcessStartInfo With {.Arguments = " /t:exe """ & tmpfile & """", .WindowStyle = ProcessWindowStyle.Hidden, .FileName = IO.Path.Combine(New IO.FileInfo(Application.ExecutablePath).Directory.Root.FullName, "WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe")}}
    10. p.Start()
    11. p.WaitForExit()
    12. Return IO.File.Exists(outpath)
    13. End Function
    14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    15. code = textbox1.text
    16. CompileCode(code, pfad & "code.vb", pfad & "code.exe")
    17. End Sub
    18. End Class


    lg Gugi