In case anyone needs this here is a full example of how I did it.
Create a form with a textbox(named "txtCode") and a button(name "cmdGenerate").
-How this works: You enter the code which will the generated .exe contain and then just press cmbButton. After that, the file .exe is generated and when launched it executes commands just like any other application.
This is the method for file generation:
Public Sub generateFile()
Dim codeProvider As New VBCodeProvider()
Dim icc As ICodeCompiler = codeProvider.CreateCompiler
Dim Output As String = "C:\Program Files\MyApp.exe"
Dim parameters As New CompilerParameters()
Dim results As CompilerResults
'Make sure we generate an EXE, not a DLL
parameters.GenerateExecutable = True
parameters.OutputAssembly = Output
parameters.CompilerOptions = ("/target:winexe" & " " & "/win32icon:" & """") & "C:\Program Files\MyIcons\Icon.ico" & """"
results = icc.CompileAssemblyFromSource(parameters, txtCode.Text)
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
End Sub
And then, just call that method after you've finished writting your code inside txtCode textbox.
The code example that goes inside txtCode is:
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