自动关机应用 [英] auto shutdown application

查看:73
本文介绍了自动关机应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个程序,在计算机完成下载和/或安装程序后,这些程序将自动关闭.因此,我决定尝试在可视C#中制作自己的作品.

我的计划:好主意很简单,在我的应用程序中,我希望用户能够为使用Richtextbox安装或下载的每个程序写下所有进程的名称.这样,应用程序可以仅跟踪选定的进程.然后,当列表中的过程完成时,它将触发一个事件,该事件将关闭计算机.

示例:假设我有Microsoft词进行自我安装.它称为的进程是msword.exe(例如).用户将在Richtextbox中键入该进程在应用程序中的名称以对其进行跟踪.完成安装后,Microsoft Word程序将退出,导致该过程结束.当我的应用程序确认该过程完成后,它将触发关机的计算机触发器.

问题:因此,除了关闭计算机外,我遇到的所有问题几乎都是:)我需要一些帮助,我不知道如何将进程添加到我的应用程序中,以便在编写时可以跟踪它放在richtextbox中.

谢谢:我会很感激任何在这里发表文章的人的帮助.

我的操作系统是Windows Vista.

Hi, I am having the need to have a program that will auto shutdown when the computer is done downloading and or installing a program. So I decided to try to make my own in visual C#.

MY Plan: Well the idea is simple, In my application I want the user to be able to write down all the process''s names for each of the programs that is being installed or downloaded using a richtextbox. that way the application can keep track of only the selected processes. Then when the processes from the list are done it will trigger an event that will shutdown the computer.

Example: lets say I have Microsoft word installing itself. The process that it is called is msword.exe(for example). The user will type in a richtextbox the name of that process in the application to track it. after it is done installing the Microsoft word program will exit causing the process to end. When my application acknowledges that the process is done then it will fire the shutdown computer trigger.

Question: So the problem that I am having is pretty much everything except turning the computer off :) I need some help, I don''t know how to add the process''s to my application so it can track it when you write it down in the richtextbox.

Thank You: I will appreciate any help coming from anyone who posts here.

my operating system is windows vista.

推荐答案



我建议进行一些更改.首先,我不会让用户键入要跟踪的进程的名称,而是向他提供系统上所有进程的列表.每个条目都有一个复选框.选中的项目将是要跟踪的项目.我还将添加一个刷新/更新按钮来更新进程列表.是否要保存所有已检查但现在丢失的进程,由您自己决定.

您可以使用
获取流程
Hi,

I would suggest a couple of changes. First of all i would not let the user type the name of the process to track but would provide him with a list of all the processes on the system. Each entry would have a checkbox. A checked item would be one to track. I''d also add a refresh/ update button to update the list of processes. It''s up to you if you''d like to save any processes that are checked but are now missing.

You can get the processes by using
using System.Diagnostics;


internal class ProcessItem
{
	public string Name { get; set; }
	public int Id { get; set; }
}

private readonly BindingList<ProcessItem> m_Processes = new BindingList<ProcessItem>();

public Form1()
{
	InitializeComponent();
	m_CheckedListBox.DataSource = m_Processes;
	m_CheckedListBox.DisplayMember = "Name";
}

private void OnRefreshClicked(object sender, EventArgs e)
{
	Process[] processlist = Process.GetProcesses();
	m_Processes.Clear();
	foreach(Process theprocess in processlist)
	{
		m_Processes.Add(new ProcessItem{Id = theprocess.Id, Name = theprocess.ProcessName});
	}
}

private void OnGetCheckedClicked(object sender, EventArgs e)
{
	foreach (var item in m_CheckedListBox.CheckedItems)
	{
		var processitem = item as ProcessItem;
		if (null != processitem)
		{
			Console.WriteLine("Process {0} ({1}) has been selected", processitem.Name, processitem.Id);
		}
	}
}



当然,m_CheckedListBox的类型为CheckedListBox,您可以轻松地将其从工具箱中删除.
绑定列表< T>确保当集合更改时,checkedListBox进行了更新;对集合的任何更改都会更新视图.

知道什么时候让我采取行动并关闭他的电脑很容易.只需获取进程列表,这样就可以(使用例如Timer)一次又一次地查看所检查的进程是否丢失并执行您的操作.
在您忙碌的时候,您可以考虑为用户提供等待一个或所有进程退出的选项.


希望这会有所帮助.

干杯,AT



Naturally the m_CheckedListBox is of type CheckedListBox which you can easily drop from the toolbox.
The BindingList<T> makes sure that the checkedListBox is updated when the collection changes so; any change to the collection will update the view.

To know when to co me in to action and close he pc is easy; just get the list of processes so once and a while (using e.g. A Timer) see if the checked processes are missing and do your thing.
While your busy you might consider giving the user the option to wait for one or all the processes to exit.


Hope this helps.

Cheers, AT


using System.Diagnostics;

//some of your other code

private void somefunction()//any functioname that you will call after checking your processes and doing all what you want
{
    Process.Start("shutdown", "/s");
}




它类似于在C ++中使用以下语句:




It is similar to using the below statement in C++:

system("shutdown /s");




foreach(在过程列表中处理过程)
{
Console.WriteLine(进程名称:{0};进程ID:{1}",theprocess.ProcessName,theprocess.Id);
}

从上面您可以获取该过程.在此之后,将这些过程存储在诸如programbble输入之类的复选框或linkbuttons上.然后您可以使用委托对其进行编码...

它会根据您的选择运行..

谢谢
sanjeev
hi

foreach(Process theprocess in processlist)
{
Console.WriteLine("Process name: {0}; Process ID: {1}", theprocess.ProcessName, theprocess.Id);
}

from above you can get the process.. after that store these process on so programbble input such check box or on linkbuttons.. then you can code this using delegates...

it will run on your choice..

thanks
sanjeev


这篇关于自动关机应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆