本文介绍了我试图制作一个vb.net应用程序,在空闲时间的x秒/分钟后关闭一些应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试制作一个vb.net windows应用程序,在空闲时间的x秒/分钟后关闭一些应用程序(没有用户) PC上的交互)。有没有人有任何示例代码来执行此操作?
谢谢。
Hi all,
I am trying to make a vb.net windows application that close some applications after x number of seconds/minutes of idle time (no user interaction) on the PC. Does anyone has any sample code to do this?
Thanks.
推荐答案
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ProcessName As String = Nothing ' Name of process
Dim ProcessFileName As String = Nothing ' Address of process
' Loop the processes list
For Each FsProcess As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
Try ' Catch any errors, deal with processes you don't have rights to close.
ProcessName = FsProcess.ProcessName.ToString
ProcessFileName = FsProcess.MainModule.FileName.ToString
Catch ex As Exception
' Exception is handled here.
End Try
Debug.WriteLine(FsProcess.ProcessName) ' For debug purpose only.
If FsProcess.ProcessName = "wmplayer" Then
FsProcess.Kill()
Debug.WriteLine("Process: " & FsProcess.ProcessName & " Was Closed.") ' For debug purpose only.
End If
Next
End Sub
C#:
C#:
private void Button1_Click(object sender, EventArgs e)
{
string ProcessName = null;
// Name of process
string ProcessFileName = null;
// Address of process
// Loop the processes list
foreach (System.Diagnostics.Process FsProcess in System.Diagnostics.Process.GetProcesses) {
// Catch any errors, deal with processes you don't have rights to close.
try {
ProcessName = FsProcess.ProcessName.ToString;
ProcessFileName = FsProcess.MainModule.FileName.ToString;
} catch (Exception ex) {
// Exception is handled here.
}
Debug.WriteLine(FsProcess.ProcessName);
// For debug purpose only.
if (FsProcess.ProcessName == "wmplayer") {
FsProcess.Kill();
Debug.WriteLine("Process: " + FsProcess.ProcessName + " Was Closed.");
// For debug purpose only.
}
}
}
如果您有任何疑问,请回复评论。希望它有所帮助。
If you have any questions, post back with a comment. Hope it helps.
这篇关于我试图制作一个vb.net应用程序,在空闲时间的x秒/分钟后关闭一些应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!