[VB.NET] 다른 응용 프로그램 실행(Run) 및 종료(Kill) > vb.net

본문 바로가기

vb.net

[기타] [VB.NET] 다른 응용 프로그램 실행(Run) 및 종료(Kill)

회원사진
하나를하더라도최선을
2022-11-04 07:24 2,859 0

본문



'example : 1
Dim SDP As System.Diagnostics.Process
 
 
'// 응용프로그램 실행
SDP = System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, "tem.exe"))
 
 
'// 프로세스 종료
SDP.Kill()
 

 
'example : 2

'// API 선언
Public Declare Function ShellExecuteA Lib "shell32.dll" (
    ByVal hWnd As IntPtr,
    ByVal lpOperation As String,
    ByVal lpFile As String,
    ByVal lpParameters As String,
    ByVal lpDirectory As String,
    ByVal nShowCmd As Integer) As IntPtr
 
 
'// 응용프로그램 실행
ShellExecuteA(Me.Handle, "open", Path.Combine(Application.StartupPath, "tem.exe"), """"4)
 
 
'// 응용프로그램 종료
KillProcess("tem.exe")
 
'// 응용프로그램 종료 및 카운트 함수
Public Function KillProcess(app_exe_Name As String, Optional ProcessCheck As Boolean = FalseAs Integer
    Dim count As Integer
    Try
        For Each Process As Object In GetObject("winmgmts:").ExecQuery("Select * from Win32_Process Where Name = '" & app_exe_Name & "'")
            count += 1
            If Not ProcessCheck Then Process.Terminate()
        Next
    Catch ex As Exception
        count += KillProcess(app_exe_Name, ProcessCheck)
    End Try
    Return count
End Function
 
 
'example : 3
 
'// 응용프로그램 실행
'※ shell 명령의 경우 공백을 Parameter 즉 Command 값 고분자로 인식하므로 경로의 양쪽을 ""로 묶어 주어야 한다.
CreateObject("wscript.shell").Run("""" & Path.Combine(Application.StartupPath, "tem.exe"& """"00)
 
 
'// 응용프로그램 종료
'example 2와 참고

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색