如何在VB.NET中启动,隐藏和结束进程? [英] How do I start, hide and end a process in VB.NET ?

查看:183
本文介绍了如何在VB.NET中启动,隐藏和结束进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,请原谅我对这个问题的无知,因为我还不熟悉编程。我想要启动,一旦启动就隐藏,并在代码中的某个点结束进程。你能指导我怎么做吗?我已经尝试使用Process类,通过它可以启动它,但是我无法隐藏和结束它。



感谢您的时间!

Hello, Please excuse my ignorance on the subject since I fairly new to programming. I want to Start, hide as soon as it starts and end a process at some point in the code. Could you please guide me how to do this ? I have tried using the Process class through which I can start it but I am having trouble hiding and ending it.

Thanks for your time !

推荐答案

启动过程是一直常用的东西,否则我们根本就没有进程。当您启动应用程序时,该过程就会启动,但它总是由其他已经执行的进程完成(系统启动过程 bootstraps 其中一些,所以你总是有一个开始)。 br $> b $ b

怎么样?请参阅:

https: //msdn.microsoft.com/en-us/library/System.Diagnostics.Process(v=vs.110).aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.diagnostics.process。 start.aspx [ ^ ]。



停止流程?这取决于你停止的意思。只有一种合法的方法可以终止进程:当执行从某个应用程序的入口点函数返回时, main 函数。这是在所有 Application.Exit ,关闭主应用程序窗口以及其他多种退出应用程序的方法之后真正发生的事情,具体取决于所有技术,语言和库。一个特殊情况可能是在进程主线程的顶层堆栈框架上运行,它具有相同的效果,也可以被认为是可接受的,特别是在一些简单的仅控制台应用程序中。请注意,它可能无法在所有情况下使用。如果除了主进程线程之外还有任意数量的非后台线程,则每个线程都将保持进程加载,继续执行。所有这些线程也应该在进程终止和卸载之前退出执行。



任何其他停止进程的方法都是件坏事。你真的可以终止(杀死)任何尚未准备好退出执行的进程。如果您没有其他选择,则可以将其视为临时措施。例如,由于一些错误,您无法找到如何终止所有这些非后台线程,或者您有一些外部进程无法正常运行(错误,质量极差),无法进行修补。这就是如何做到这一点: https://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill%28v=vs.110%29.aspx [ ^ ]。

如果您的调用进程具有足够的权限来杀死另一个进程,则它可以用于调用进程或其他进程。 不要这样做!总是尝试修复这些错误。



如果你需要通过另一个进程停止一个进程,唯一合法的方法就是这个:您需要将一些通知传递给另一个进程以请求它自行停止。然后,最终,该进程应该以一些标准方式退出执行(最终,退出入口点函数)。当然,这个过程应该是为这种合作而设计的。在所有情况下,通知机制是IPC设施之一,其中有很多,例如命名管道,消息,套接字。



最后,我们应该甚至讨论隐藏过程?我不会。我认为这只是一些恶意软件尝试过的黑客行为。我会在这一点上停止这个话题。如果你能提到做这些事情的任何合法目的,我会很乐意讨论它。但是如果你只是想隐藏一些窗口,请参阅我对上述问题的评论。



-SA
Starting process is the usual thing which is always used, otherwise we would not have processes at all. The process is started when you start the application, but it is always done by some other, already executing process (the system startup process bootstraps some of them, so you always have one to start with).

How? Please see:
https://msdn.microsoft.com/en-us/library/System.Diagnostics.Process(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx[^].

Stopping process? It depends what do you mean by stopping. There is only one legitimate way of terminating the process: when execution returns from the entry-point function of some application, main function. This is what really happens on after all those Application.Exit, closing of the main application window, and other numerous ways of quitting the applications, depending on all the technologies, languages and libraries. One special case is perhaps running on the top stack frame of the process's main thread which has the same effect and can also be considered acceptable, especially in some simple console-only applications. Note that it may not work in all cases. If you have any number of non-background threads other then main process thread, each of them will keep the process loaded, continuing the execution. All those threads should also exit their execution before the process can be terminated and unloaded.

Any other way of stopping the process is a bad thing. You really can terminate (kill) any process which is not ready to quit its execution. It can be considered only as a temporary measure if you have no other choice. For example, due to some bugs, you failed to find how to terminate all those non-background threads, or you have some external process which does not behave properly (bugs, extremely poor quality), not accessible for your patching. This is how this bad thing can be done: https://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill%28v=vs.110%29.aspx[^].
This can work for both calling process or some other process, if your calling process has enough privileges to kill another one. Don't do it! Always try to fix those bugs.

If you need to stop one process by another process, the only legitimate way is this: you need to pass some notification to another process to request it to stop itself. Then, eventually, that process should quit execution in some of standard ways of doing so (ultimately, exit entry-point function). Naturally, that process should be designed for such kind of collaboration. In all cases, the notification mechanism is one of the IPC facilities, there are many of them, such as named pipe, messages, sockets.

And finally, shall we even discuss hiding of the process? I would not. I think this is the hack only attempted by some malicious software. I would stop this topic at this point. If you can mention any legitimate purpose of doing such things, I will gladly discuss it. But if you just want to hide some windows, please see my comment to the question above.

—SA


这篇关于如何在VB.NET中启动,隐藏和结束进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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