2014-02-19 2 views
0

VB .NET 프로젝트에서 exe 파일을 실행하는 것에 대한 질문이 있습니다.프로젝트에서 VB.NET에서 VB 유형의 exe 파일을 실행하십시오.

나는 이전에 VB.NET 프로젝트의 내부에서 EXE 파일을 실행 기사 http://www.dreamincode.net/forums/topic/244460-how-to-run-a-exe-file-from-inside-a-vs2010-project/

를 참조하십시오.

나는

Process.Start를을 ('myprogram.exe로 \은 My.Resources ") 및 System.Diagnostics.Process.Start (My.Computer.FileSystem.SpecialDirectories.Desktop &"\ 화면 사용 .EXE ")

그러나 EXE 파일을 실행, 어떤 일이 없습니다. 따라서, 나는 그 경로가 EXE 파일 여기

를 실행하는 잘못 가정하는 것은 내가, 제대로 실행중인 I 수동으로 EXE 파일을 클릭 exe 파일

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 

If My.Computer.FileSystem.FileExists((My.Computer.FileSystem.SpecialDirectories.Desktop & "\screen.exe")) Then 
    MsgBox("yes") 
     Process.Start((My.Computer.FileSystem.SpecialDirectories.Desktop & "\screen.exe")) 
    Else 
     MsgBox("np") 
    End If 

를 실행 한 것입니다. 또한 if 문을 사용하여 파일이 있는지 확인하십시오.

exe ​​파일이 있음을 나타내는 true를 반환합니다.

그러나 Visual Studio 2012 (VB.NET) 프로젝트에서 실행할 때. 오류가 없으며 파일을 실행하지 않는 것 같습니다.

나는이 이런 일이 왜

사람이 알고 있나요 일어날 이유를 정말 확실하지 않다?

+1

Process.S에 대한 호출의 반환 값은 무엇입니까? 타르트? –

+0

내 샘플 EXE 파일은 스크린 샷을 찍어야합니다. exe 파일을 두 번 클릭하면. 그것은 일하고 있었다. 그러나, 나는 exe 파일을 실행하는 내 VB.NET 프로젝트를 실행할 때. 그냥 아무 일도 일어나지 ... –

+0

나는 EXE 파일이 그것을 반환 믿지 않아. EXE 파일로 스크린 샷 찍기 –

답변

1

나는 이미 이것을 테스트하고 있으며, 내 로컬 PC에서 실행됩니다. exe ​​파일의 경로가 올바른지 확인하십시오.

Process.Start("FolderPath\MyProgram.exe") 

코드 예제를 다운로드하려면이 사이트를 확인하십시오. Example Code

0

먼저 리소스는 파일이 아니므로 Process.Start를 사용하여 실행할 수 없습니다. 이렇게하면 파일 만 실행되므로 자신의 프로그램 파일 내의 바이트 만 리소스를 추출하여 별도의 파일로 저장해야합니다. 그것은 Windows의 보안 문제이기 때문에 허용되지 않을 수도 있습니다.

실제 EXE가 제대로 실행되지 않는 한 가능한 원인은 잘못된 작업 디렉터리입니다. ProcessStartInfo 개체를 만들고 실행중인 EXE가 들어있는 폴더로 WorkingDirectory 속성을 설정해보십시오. 의존성에 대한 작업 디렉토리를 찾는 프로그램의 문제점을 해결할 수 있습니다.

0

리소스를 실행하거나 기존 실행 파일을 실행하는 경우 실제로 필요한 것이 분명하지 않습니다.

' Load Resource To Disk 
' (By Elektro) 
' 
' Usage Examples: 
' LoadResourceToDisk(My.Resources.Program, "C:\Program.exe") 
' Process.Start("C:\Program.exe") 
' 
''' <summary> 
''' Loads a resource to disk. 
''' </summary> 
''' <param name="Resource"> 
''' Indicates the resource to load. 
''' </param> 
''' <param name="TargetFile"> 
''' Indicates the target file to save the resource. 
''' The target file is overwritten. 
''' </param> 
''' <returns> 
''' <c>true</c> if operation succeeds, <c>false</c> otherwise. 
''' </returns> 
''' <exception cref="Exception"></exception> 
Private Function LoadResourceToDisk(ByVal Resource As Byte(), 
            ByVal TargetFile As String) As Boolean 

    Try 
     Dim BufferFileStream As New IO.FileStream(TargetFile, IO.FileMode.Create, IO.FileAccess.Write) 
     BufferFileStream.Write(Resource, 0, Resource.Length) 
     BufferFileStream.Close() 
     Return True 

    Catch ex As Exception 
     Throw New Exception(ex.Message, ex.InnerException) 
     Return False 

    End Try 

End Function 

사용법 :

LoadResourceToDisk(My.Resources.Program, "C:\Program.exe") 
    Process.Start("C:\Program.exe") 

그리고 당신이 할 수있는 기존 파일을 시작 :

는이 같은 디스크에로드 할 수 있습니다 자원에있는 EXE를 시작하려면
Private Sub Test() Handles Button1.Click 

    Dim ExePath As String = 
    IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Screen.exe") 

    Dim Result As Integer 

    Using p As New Process() 

     With p.StartInfo 
      .FileName = ExePath 
      .Arguments = "" 
     End With 

     p.Start() 
     p.WaitForExit() 

     Result = p.ExitCode 

    End Using 

    MsgBox(String.Format("ExitCode: {0}", Result)) 

End Sub 
0
File.WriteAllBytes(Application.StartupPath & "\FilesNameToSaveTo.exe", My.Resources.ResourceFilesName) 


Process.Start(Application.Startpath & "\FilesNameToSaveTo.exe") 
+0

답변을 편집하고 표시되는 코드가하는 것과 그 코드가 질문에 대답하는 이유/방법을 설명하면 정말 도움이 될 수 있습니다. –

관련 문제