简体   繁体   English

关闭所有进程

[英]Close all processes

I'm trying to make a command which will close all processes, but it will not work for me. 我正在尝试创建一个将关闭所有进程的命令,但对我而言不起作用。

#include "StdAfx.h"

int _tmain(int argc, _TCHAR* argv[])
{

     // Get the list of process identifiers.
    DWORD ExitCode;
    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
    {
        return 1;
    }

     // Calculate how many process identifiers were returned.
    cProcesses = cbNeeded / sizeof(DWORD);

    // exit each process.

    for ( i = 0; i < cProcesses; i++ )
    {
        std::cout<<"end";
        if( aProcesses[i] != 0 )
        {
            GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
            ExitProcess(ExitCode);
        }
    }

}

In addition, I get those errors: 另外,我得到那些错误:

> 'check2.exe': Loaded 'C:\Users\Barak Shriky\Documents\Visual Studio 2010\Projects\check2\Debug\check2.exe', Symbols loaded.
'check2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Symbols loaded (source information stripped).
The program '[3292] check2.exe: Native' has exited with code -858993460 (0xcccccccc).

Can someone please help me with this issue? 有人可以帮我解决这个问题吗?

1) You are not getting any errors 1)您没有任何错误

2) ExitProcess is ending your process. 2) ExitProcess正在结束您的过程。 Please read the documentation. 请阅读文档。

Looks to me like it's working just fine - you just haven't got symbols installed for some system DLL's, which is normal. 在我看来,它的工作原理很好-您只是没有为某些系统DLL安装符号,这很正常。

Of course, you would get a more meaningful message of why the process exited if you actually set ExitCode to something - say ExitCode = 0xDeadBeef; 当然,如果您实际上将ExitCode设置为某种值,您将得到一个更有意义的消息,说明为什么退出该进程-例如ExitCode = 0xDeadBeef; - and then you would see that it was YOUR process that killed itself. -然后您会发现是您的过程杀死了自己。

Doing this seems like a very bad thing to do (assuming it is "successful" in closing the process in the first place), since there are certainly plenty of processes in Windows that when stopped causes the rest of the system to not work very well. 这样做似乎是一件很不好的事情(首先假设它“成功”关闭了进程),因为Windows中肯定有很多进程,当这些进程停止时会导致系统其余部分无法正常运行。 Such as the page-in/out process, for example, which is also used to load/unload executables. 例如,例如页面入/出过程,它也用于加载/卸载可执行文件。 Being SLIGHTLY more selective in which processes you kill will probably be useful. 在杀死的进程中稍微更具选择性可能会很有用。

see the code below where I used terminate process... 请参阅下面我使用终止过程的代码...

// exit each process.

for ( i = 0; i < cProcesses; i++ )
{
    std::cout<<"end";
    if( aProcesses[i] != 0)
    {
       GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
      TerminateProcess(aProcesses[i], ExitCode);

    }
}
}

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

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