VB-Code kompilieren

    • VB.NET

    Es gibt 87 Antworten in diesem Thema. Der letzte Beitrag () ist von teddygun300.

      VB-Code kompilieren

      Hallo,

      hier ein Code mit dem man VB-Code zu einer Exe kompilieren kann. Voraussetzung ist das Framework 3.5.

      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

      Ansonsten lässt sich auch gut der System.CodeDom.Compiler.CodeCompiler oder der Microsoft.VisualBasic.VBCodeProvider nutzen.

      Hier einige Beispielcodes zum testen:

      VB.NET-Quellcode

      1. Module Module1
      2. Sub Main()
      3. System.Console.WriteLine("Mit dem Vb Codecompiler kompilierter Source!")
      4. Console.Writeline("Zahl eingeben: ")
      5. Do Until IsNumeric(Console.Readline)
      6. Console.Writeline("Zahl eingeben: ")
      7. Loop
      8. Console.Writeline("Zahl gültig.")
      9. System.Console.ReadLine()
      10. SchreibHallo()
      11. End Sub
      12. Sub SchreibHallo()
      13. Console.Writeline("Hallo!")
      14. Console.Read()
      15. End Sub
      16. End Module

      VB.NET-Quellcode

      1. Module Test
      2. Sub Main()
      3. MsgBox("test")
      4. Sagnochwas
      5. End Sub
      6. Sub Sagnochwas()
      7. MsgBox("hallo")
      8. End Sub
      9. End Module

      VB.NET-Quellcode

      1. Module Test
      2. Sub Main()
      3. Console.Write("Dein Name: ")
      4. Dim Name As String = Console.Readline
      5. MsgBox("Hallo " & Name)
      6. End Sub
      7. End Module

      VB.NET-Quellcode

      1. Module Test
      2. Sub Main()
      3. MsgBox(test(False))
      4. End Sub
      5. Function test(ByVal true2 As Boolean) As String
      6. Return If(true2, "blalba", "utztötötö")
      7. End Function
      8. End Module

      VB.NET-Quellcode

      1. Module MyModule
      2. Sub Main()
      3. For i As Integer=1 To 100000
      4. Console.Writeline(Convert.ToString(i))
      5. Next
      6. End Sub
      7. End Module

      VB.NET-Quellcode

      1. Module MyModule
      2. Sub Main()
      3. Console.Writeline(Convert.ToString(Math.Log(50)))
      4. Console.Read()
      5. End
      6. End Sub
      7. End Module


      Mit C# sieht's ähnlich aus.

      Viel Spaß damit ;)

      Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „kevin89“ ()

      @serials: Dann ersetz diesen Code

      VB.NET-Quellcode

      1. Shell("C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe /t:exe C:\Builts\temp.vb", AppWinStyle.Hide) ' kompilieren
      mal durch diesen hier:

      VB.NET-Quellcode

      1. Shell(Environ("systemroot") & "\Microsoft.NET\Framework\v3.5\vbc.exe /t:exe C:\Builts\temp.vb", AppWinStyle.Hide) ' kompilieren
      Ich habe aber deine Codes genommen :P

      So sieht mein Code aus

      VB.NET-Quellcode

      1. Private Sub vb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vb.Click
      2. 'Der Kompilierenden Code
      3. Dim code As String = TextBox_code.Text
      4. 'Überprüfen ob Visual Basic installiert ist
      5. Dim vb_install As New FileInfo(Environ("systemroot") & "\Microsoft.NET\Framework\v3.5\vbc.exe")
      6. 'Visual Basic Ordner erstellen
      7. My.Computer.FileSystem.CreateDirectory("C:\Build\Visual Basic")
      8. 'Visual Basic Datei (*.vb) erstellen
      9. My.Computer.FileSystem.WriteAllText("C:\Build\Visual Basic\Build.vb", code, False)
      10. 'Kompilieren (VB.NET = vbc.exe)
      11. If vb_install.Exists Then
      12. Shell(Environ("systemroot") & "\Microsoft.NET\Framework\v3.5\vbc.exe /t:exe C:\Build\Visual Basic\Build.vb", AppWinStyle.Hide)
      13. Else
      14. MessageBox.Show("Sie haben Visual Basic nicht installiert !")
      15. End If
      16. End Sub


      Habe auch 2 sachen von hier versucht aber die haben auch net gefuntz
      msdn.microsoft.com/de-de/library/4dehewf5.aspx
      Fw 3.5 ist doch drauf oder :D

      Ist da, wenn du das kompilieren startest, kurz eine Konsole zu sehen?

      Lösch mal alles im Button und hau das rein:

      VB.NET-Quellcode

      1. Dim code As String = TextBox1.Text
      2. If My.Computer.FileSystem.DirectoryExists("C:\Builts") = False Then
      3. My.Computer.FileSystem.CreateDirectory("C:\Builts")
      4. End If
      5. My.Computer.FileSystem.WriteAllText("C:\Builts\test.vb", code, False)
      6. Shell("C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe /t:exe C:\Builts\temp.vb", AppWinStyle.Hide)

      und nix ändern/anpassen :P ^^