如何在关闭所有正在运行的任务时阻止系统关闭

如何在关闭所有正在运行的任务时阻止系统关闭

本文介绍了如何在关闭所有正在运行的任务时阻止系统关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查我的下面的代码,在这里选择进程逐个杀死进程,但我需要关闭我的列表框中的所有任务..所以请你帮助我



Thanx提前





Dim p As System.Diagnostics.Process



For Each p In System.Diagnostics.Process.GetProcesses()



Dim arr()As String = _

lstProcesses .SelectedItem.ToString()。分割( - )



Dim sProcess As String = arr(0).Trim()

Dim iId As Integer = Convert.ToInt32(arr(1).Trim())



如果p.ProcessName = sProcess并且p.Id = iId那么

p.Kill()

结束如果



下一页





我正在尝试使用vb.net关闭计算机中的所有正在运行的任务,但我遇到问题,当我尝试关闭正在运行的任务然后我的系统还关机..所以任何人都可以帮我在运行应用程序时如何阻止我的系统关闭。





提前致谢

please check my below code here kill process one by one on selecting the process, but i need to close all task from my listbox..so plz can u help me

Thanx in advance


Dim p As System.Diagnostics.Process

For Each p In System.Diagnostics.Process.GetProcesses()

Dim arr() As String = _
lstProcesses.SelectedItem.ToString().Split("-")

Dim sProcess As String = arr(0).Trim()
Dim iId As Integer = Convert.ToInt32(arr(1).Trim())

If p.ProcessName = sProcess And p.Id = iId Then
p.Kill()
End If

Next


I am trying to closing all the running task in my computer using vb.net, but i am facing problem, when i try to closing the running task then my system also shutdown..so plz any one can help me how can prevent my system close while running the application.


Thanks in advance

推荐答案

For Each p As Process In Process.GetProcesses
    If p.MainWindowTitle.Length > 0 AndAlso p.SessionId > 0 Then
        lstProcesses.Items.Add(p.ProcessName & " | " & p.MainWindowTitle)
    End If
Next





为什么你需要这样做?也许对此有所了解将有助于我们为您提供最佳实践。



您可能需要学习Win32 SDK API以查找可用于区分用户应用程序和服务以及其他操作系统组件的API。



此外,在没有首先提示用户保存过程工作的情况下终止进程被视为错误形式。



Why do you need to do this? Perhaps an insight into that would help us provide you best practices.

You may have to study the Win32 SDK APIs to find APIs that you can use to distinguish between user applications and services and other operating system components.

Also, killing processes without first prompting the user to save in process work is considered "bad form".


这篇关于如何在关闭所有正在运行的任务时阻止系统关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:06