3

bluestacks アプリケーションを開閉するプログラムを作成しようとしています。閉じるとは、アプリケーションを完全に終了することを意味します。bluestacks アプリを終了しても、プロセスは再起動するだけです。私が殺そうとしているプロセスは次のとおりです。

  1. 「HD-BlockDevice.exe」
  2. 「HD-Agent.exe」
  3. 「HD-LogRotatorService.exe」
  4. 「HD-UpdaterService.exe」

最初のプロセスを手動で kill すると、2 ~ 3 のプロセスを除いて他のプロセスが終了します。アプリケーションを閉じるたびに 4 つのプロセスを強制終了するのはちょっと面倒なので、これを作成しています。これが私のコードです

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. 私が調べたプロセスキルのいずれかが機能しません(とにかく、コードでコメントするために作成したものです)
4

1 に答える 1

1

別の角度から見た後、最終的にコマンドプロンプトでそれを殺すというアイデアを見つけました...そしてネットでそれを行う方法をたくさん読んだ後、ついにそれを機能させる答えを見つけました...

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
于 2015-06-17T01:57:41.533 に答える