누구나 여기에 필요한 경우에는 내가 어떻게했는지에 대한 전체 예가 나와 있습니다.
는 ("txtCode"라는 이름의)를
텍스트 상자과
버튼 (이름 "cmdGenerate")와 양식을 만듭니다.
- 작동 방식 : 생성 된 .exe에 포함될 코드를 입력 한 다음 cmbButton을 누릅니다. 그 후, .exe 파일이 생성되고 실행되면 다른 응용 프로그램과 마찬가지로 명령이 실행됩니다. 당신이 txtCode 텍스트 상자 내부 코드를을 writting 마친 후
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
그리고, 그냥 그 메소드를 호출
이
파일 생성을위한 방법이다.
txtCode 내부 이동 코드 예제는 다음과 같습니다
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
의
가능한 복제 [? 동적으로 소스 코드에서 컴파일 된 .NET exe 인을 만들] (http://stackoverflow.com/questions/3591587/ 소스 코드에서 동적으로 작성 - 컴파일 된 - net-exe) – GSerg
@GSerg에서 언급 한 복제본을 사용하십시오. "CSharp"를 "VisualBasic"(하나의 대답)으로 대체하거나 "csc"를 "vbc"로 대체하십시오. –