如何制作一个在 Windows 中不可能被杀死的程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/922207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:33:58  来源:igfitidea点击:

How can I make a program that's impossible to be killed in Windows?

c#.netwindowsprocess

提问by David Hofmann

We are making a Jabber client for our internal use in our company and somehow we need to catch the moment when the user tries to kill the program to actually restart it or just make impossible for the user to kill the client.

我们正在为我们公司的内部使用制作一个 Jabber 客户端,我们需要以某种方式抓住用户试图杀死程序以实际重新启动它或让用户无法杀死客户端的时刻。

Is this possible?

这可能吗?

Our Jabber client will be written in C#.

我们的 Jabber 客户端将使用 C# 编写。

How would I go about accomplishing this?

我将如何去完成这个?

回答by Rob Allen

What you are asking for has implications far beyond what you are being asked to accomplish. For example, if the process cannot be killed, how can Windows shut down normally?

你所要求的意义远远超出你被要求完成的事情。比如进程杀不掉,Windows怎么才能正常关机?

I don't know your boss, so you will have to gauge their level of understanding for yourself. If a user/manager asked me for this, I would have to probe deeper to find what they really mean. My suspicion is that your users want the default close behavior to minimize to the system tray rather than exit the program, similar to most instant message clients, rather then not be able to ever close the program at all.

我不了解你的老板,所以你必须自己衡量他们的理解程度。如果用户/经理问我这个问题,我将不得不深入探究以找出它们的真正含义。我怀疑您的用户希望默认关闭行为最小化到系统托盘而不是退出程序,类似于大多数即时消息客户端,而不是根本无法关闭程序。

回答by Russ Bradberry

let me first say, this is a horrible idea.

首先让我说,这是一个可怕的想法。

but...if you must do it, the way I see malicious software and spam hounds do it is to create 3 running processes, one is the main process and the other two will monitor and restart any killed process. it's very difficult for the average user to kill 3 processes simultaneously.

但是...如果你必须这样做,我看到恶意软件和垃圾邮件猎犬的做法是创建 3 个正在运行的进程,一个是主进程,另外两个将监视并重新启动任何被杀死的进程。普通用户很难同时杀死 3 个进程。

回答by David

Sounds like a virus.

听起来像病毒。

回答by Jab

Since this is internal, you could create a separate windows service that monitors the active processes. If the process of your jabber client isn't there, you could just relaunch it.

由于这是内部的,您可以创建一个单独的 Windows 服务来监视活动进程。如果您的 jabber 客户端的进程不存在,您可以重新启动它。

Then use permissions to keep them from accessing the Windows Service to disable it.

然后使用权限阻止他们访问 Windows 服务以禁用它。

回答by J. Polfer

I think you should go ask the requirement designer what they mean by app that is impossible to "kill." What are they getting at with the word "kill"?

我认为你应该去问需求设计师他们所说的不可能“杀死”的应用程序是什么意思。他们用“杀”这个词是什么意思?

  • Not allowing a user to close their program
    • Prevent standard use of X button in window?
    • Minimize to task tray?
    • Not allow them to close the app in Task Manager?
  • Not allowing the OS to close their program
  • 不允许用户关闭他们的程序
    • 防止在窗口中标准使用 X 按钮?
    • 最小化到任务托盘?
    • 不允许他们在任务管理器中关闭应用程序?
  • 不允许操作系统关闭他们的程序

The requirement is ambiguous enough that I'd go talk to the requirement designer/boss to get a better idea of what they want.

需求很模糊,我会去和需求设计师/老板谈谈,以更好地了解他们想要什么。

回答by Andrew Hare

Not only does this sound like a bad idea (it is abusive to your users) but you will not be able to prevent users from killing the process itself.

这不仅听起来像一个坏主意(这对您的用户来说是一种侮辱),而且您将无法阻止用户自行终止进程。

You would have to run two separate processes - one to run the application and a second one to monitor the first one and restart it if necessary.

您必须运行两个单独的进程 - 一个运行应用程序,第二个进程监视第一个进程并在必要时重新启动它。

回答by Adam Rosenfield

You can't. You can make it harder, but not impossible. See The arms race between programs and users.

你不能。你可以让它更难,但并非不可能。请参阅程序和用户之间的军备竞赛

回答by MatthewMartin

You'll have to reduce their user rights until they can't kill processes.

您必须减少他们的用户权限,直到他们无法终止进程。

回答by Jeffrey Knight

Control it with a Windows Service. Easy to do in C#. Lock down permissions to stop the service.

使用 Windows 服务控制它。在 C# 中很容易做到。锁定权限以停止服务。

Note: I think the answers of "this is impossible/horrible/evil" are perhaps missing your point. A service is specifically designed 'keep going', which is what you're asking about.

注意:我认为“这是不可能的/可怕的/邪恶的”的答案可能没有说明您的观点。一项服务是专门设计的“继续前进”,这就是您要问的。

回答by Chris K

More importantly, WHY are you rewriting a jabber client when so many good ones, like Miranda and Pidgin already exist? If it's for logging, you can easily do that server side on your Jabber server, and not rely on the clients.

更重要的是,既然已经有这么多好的客户端,比如 Miranda 和 Pidgin,你为什么要重写一个 jabber 客户端?如果是用于日志记录,您可以轻松地在 Jabber 服务器上进行服务器端操作,而无需依赖客户端。

If it's to prevent other IM services, robust firewall rules will help stop that (but it won't prevent it from the super geniuses who'll proxy AIM+Gtalk over https to their home servers).

如果是为了阻止其他 IM 服务,强大的防火墙规则将有助于阻止它(但它不会阻止超级天才通过 https 将 AIM+Gtalk 代理到他们的家庭服务器)。