process - 杀死进程/结束bluestacks进程

标签 process kill bluestacks

我正在尝试制作一个可以打开和关闭 bluestacks 应用程序的程序。关闭意味着完全退出应用程序。因为即使您退出 bluestacks 应用程序,该过程也会重新启动。 我试图杀死的进程是:

  1. “HD-BlockDevice.exe”
  2. "HD-Agent.exe"
  3. "HD-LogRotatorService.exe"
  4. "HD-UpdaterService.exe"

当我手动杀死第一个进程时,其他进程将关闭,除了 2~3 个。每次关闭应用程序时都要杀死四个进程有点痛苦,所以我创建了这个。 这是我的代码

Public Class Form1
Dim p() As Process
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     Timer_ProcessCheck.Start()
End Sub

Private Sub Timer_ProcessCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_ProcessCheck.Tick
    p = Process.GetProcessesByName("HD-BlockDevice.exe")
    If p.Count > 0 Then
        ' Process is running
        'Button_Close.Enabled = True
    Else
        ' Process is not running
        'Button_Close.Enabled = False
    End If
End Sub

Private Sub Button_Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Open.Click
    Process.Start("C:\Program Files (x86)\BlueStacks\HD-StartLauncher.exe")
End Sub

Private Sub Button_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Close.Click
    'p = Process.GetProcessesByName("HD-BlockDevice.exe")

    'p.kill()
    'p.close()

    'While p.Length > 0
    'For i As Integer = p.Length - 1 To 0 Step -1
    'p(i).CloseMainWindow()

    'Next

    'p = Process.GetProcessesByName("HD-BlockDevice.exe")
    'End While

    'Timer_ProcessKill.Start()

End Sub

Private Sub Timer_ProcessKill_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer_ProcessKill.Tick
    For Each prog As Process In Process.GetProcesses
        If prog.ProcessName = "HD-BlockDevice.exe" Then
            prog.Kill()
        End If
    Next
End Sub
End Class

我的问题是:

  1. 我的进程检查器无法工作(当进程已经存在时它不会启用关闭按钮)
  2. 我查找的任何终止进程都不起作用(这些是我在代码中注释的那些)

最佳答案

好吧,在从不同的角度看它之后,我终于找到了一个通过命令提示符杀死它的想法......在网上阅读了很多如何做到这一点之后,我终于找到了让它工作的答案......

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim working_area As Rectangle = SystemInformation.WorkingArea
    Dim newW As Integer = working_area.Left + working_area.Width - Me.Width
    Dim newH As Integer = working_area.Top + working_area.Height - Me.Height
    Me.Location = New Point(newW, newH)
    Timer_ProcessCheck.Start()
End Sub

Private Sub Button_Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Open.Click
    Process.Start("C:\Program Files (x86)\BlueStacks\HD-StartLauncher.exe")
End Sub

Private Sub Button_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Close.Click
    Timer_ProcessCheck.Stop()
    Process.Start("cmd.exe", "/c taskkill /IM HD-BlockDevice.exe /f")
    Process.Start("cmd.exe", "/c taskkill /IM HD-Agent.exe /f")
    Process.Start("cmd.exe", "/c taskkill /IM HD-LogRotatorService.exe /f")
    Process.Start("cmd.exe", "/c taskkill /IM HD-UpdaterService.exe /f")
    Me.Close()
End Sub

Private Sub Timer_ProcessCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_ProcessCheck.Tick
    Dim oProcess As New Process()
    Dim oStartInfo As New ProcessStartInfo("tasklist")
    oStartInfo.CreateNoWindow = True
    oStartInfo.UseShellExecute = False
    oStartInfo.RedirectStandardOutput = True
    oProcess.StartInfo = oStartInfo
    oProcess.Start()

    Dim sOutput As String
    Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
        sOutput = oStreamReader.ReadToEnd()
    End Using
    If sOutput.Contains("HD-BlockDevice.exe") Then
        Button_Close.Enabled = True
    Else
        Button_Close.Enabled = False
    End If
End Sub 
End Class

关于process - 杀死进程/结束bluestacks进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30820710/

相关文章:

java - 从 java 执行外部进程。进程终止后得到输出,但在终止前需要它

ruby - Ubuntu 12.04 中找不到 Killproc 命令错误

c - 如何多次向 child 发送信号以避免僵尸状态? C语言

android - android 会杀死我以 root 身份运行的守护进程吗?

c# - Process.WaitForExit 方法在 Process.Close 后抛出 InvalidOperationException

c - Unix 进程 - 编译和运行 c 程序

c# - Appdomain 与流程的性能优势?

android - 更改 Bluestack : portrait/landscape mode 的方向

java - Android、Bluestacks : "open failed: EISDIR (Is a directory)"