2015-06-13 161 views
2

我正在嘗試製作一個程序來打開和關閉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. 任何進程殺我看起來不起作用(這些是我已經在代碼中發表評論的人)
+0

ahm謝謝編輯我的帖子...我沒有真正理解如何把「進入」那裏,我希望你能教我...提前感謝 – pwalaako2

回答

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