简体   繁体   English

需要关闭所有正在运行的应用程序而不使用c#应用程序的Windows注销

[英]need to close all running applications without using windows logoff from c# application

i need to close all open applications in windows while my application closes how to i do that using c# 我需要关闭Windows中所有打开的应用程序,而我的应用程序关闭我如何使用c#

i am implementing login/logoff functionality in my application itself instead of windows login/logoff so that i need to close all applications while logoff clicked in my application and pass control to my application after that 我正在我的应用程序本身而不是Windows登录/注销中实现登录/注销功能,这样我需要关闭所有应用程序,同时在我的应用程序中单击注销并将控制权传递给我的应用程序之后

using System.Diagnostics;

Process [] localAll = Process.GetProcesses();
foreach(Process p in localAll)
{
    p.Kill();
}

But you'd probably have to put in some kind of filter to avoid killing certain processes since otherwise the machine might get a bit upset. 但是你可能不得不放入某种过滤器以避免杀死某些进程,否则机器可能会有点不高兴。

For whatever reason you want to do this. 无论出于何种原因,你想要这样做。 This is a bit funnier way to do it! 这是一个有趣的方式来做到这一点!

using System.Diagnostics;

Parallel.ForEach(Process.GetProcesses(), process => process.Kill());

Don't run this with an elevated process though; 不要在升级过程中运行它; will probably caus your OS to crash. 可能会导致您的操作系统崩溃。

You definitely do NOT want to just loop over the system processes and kill them all. 你绝对不想只是循环系统进程并将它们全部杀掉。 There are plenty of things running that should not be killed. 有很多东西不应该被杀死。 If you 'log out' in windows then log in under another user, there are a lot of processes that stay running at the system level and are shared by all logins. 如果您在Windows中“注销”然后在另一个用户下登录,则有许多进程在系统级别保持运行并由所有登录共享。

As a good example, if I look in Windows Task Manager at the processes that my current user owns (not system), then I have ATI Catalyst Control running, the Synaptics app for my touchpad, a Logitech app for my mouse, something fo the Bluetooth stack, something for the Audio system, a Dell wireless lan interface management thing... If I kill all those, I suspect my peripheral devices will start behaving strangely, even if another user logs in after me. 举一个很好的例子,如果我在Windows任务管理器中查看我当前用户所拥有的进程(而不是系统),那么我将运行ATI Catalyst Control,触摸板的Synaptics应用程序,我的鼠标的Logitech应用程序,以及蓝牙堆栈,音频系统的东西,戴尔无线局域网界面管理的东西...如果我杀了所有这些,我怀疑我的外围设备将开始表现奇怪,即使其他用户登录我。


Could you just call the actual Windows LogOut stuff with P/Invoke, as suggested here ? 你可以只调用实际的Windows注销的东西用的P / Invoke,如建议在这里 That way Windows itself can do... well, whatever it does when a user logs out, instead of you having to deal with it yourself. 这样,Windows本身就可以做到......好吧, 无论用户何时注销,都可以自己处理。

At worst , I would try to collect up the things that were started by Windows during startup. 在最坏的情况下 ,我会尝试收集启动时Windows启动的内容。 The 'Statup' items from the StartMenu: StartMenu中的'Statup'项:

C:\\Users\\User_Name\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup C:\\ Users \\ User_Name \\ AppData \\ Roaming \\ Microsoft \\ Windows \\ Start Menu \\ Programs \\ Startup

and the items from the registry at: 和注册表中的项目:

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run HKEY_CURRENT_USER \\软件\\微软\\的Windows \\ CurrentVersion \\ Run中

Then loop over the running processes and see which really belong to this user and only stop those. 然后遍历正在运行的进程,看看哪个真正属于这个用户并且只停止那些用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM