Как определить завершенный процесс Windows, если у меня все еще есть свой PID?

6956
miroxlav

Предыстория: В середине моей работы неожиданно появилось лицензионное соглашение на установку «Microsoft Mouse and Keyboard Center». Я хотел бы понять, какой процесс запустил установку, но, используя Process Explorer, я увидел, что он исчез, и мне удалось найти только его PID (см. Скриншот).

Вопрос:

Если вы используете Process Explorer, вы, возможно, знаете ситуацию, когда родительский процесс процесса больше не существует, и вы можете видеть только его PID:

Как определить завершенный процесс Windows, если у меня все еще есть свой PID?

Существуют ли какие-либо журналы Windows, содержащие связь PID с запущенным процессом, чтобы я мог узнать, какой процесс выполнялся под данным PID?

Предпочтительно меня интересуют сценарии, где я не ожидал этого, поэтому я не использовал Process Monitor для захвата событий в системе.

14

3 ответа на вопрос

11
DavidPostill

Are there some Windows logs containing association of PID to running process

By default there are no such logs. However you can enable Process Tracking Events in the Windows Security Event Log.

Notes:


How to Use Process Tracking Events in the Windows Security Log

In Windows 2003/XP you get these events by simply enabling the Process Tracking audit policy.

In Windows 7/2008+ you need to enable the Audit Process Creation and, optionally, the Audit Process Termination subcategories which you’ll find under Advanced Audit Policy Configuration in group policy objects.

These events are incredibly valuable because they give a comprehensive audit trail of every time any executable on the system is started as a process. You can even determine how long the process ran by linking the process creation event to the process termination event using the Process ID found in both events. Examples of both events are shown below.

enter image description here

Source How to Use Process Tracking Events in the Windows Security Log


How to enable Audit Process Creation

  1. Run gpedit.msc

  2. Select "Windows Settings" > "Security Settings" > "Local Policies" > "Audit Policy"

    enter image description here

  3. Right click "Audit process tracking" and select "Properties"

  4. Check "Success" and click "OK"

    enter image description here


What is Audit Process Tracking

This security setting determines whether the OS audits process-related events such as process creation, process termination, handle duplication, and indirect object access.

If this policy setting is defined, the administrator can specify whether to audit only successes, only failures, both successes and failures, or to not audit these events at all (i.e. neither successes nor failures).

If Success auditing is enabled, an audit entry is generated each time the OS performs one of these process-related activities.

If Failure auditing is enabled, an audit entry is generated each time the OS fails to perform one of these activities.

Default: No auditing

Important: For more control over auditing policies, use the settings in the Advanced Audit Policy Configuration node. For more information about Advanced Audit Policy Configuration, see http://go.microsoft.com/fwlink/?LinkId=140969.

Дэйв, возможно, ты мог бы использовать [подход «самый быстрый пистолет на западе»] (http://meta.stackexchange.com/a/9758/253161). Пока вы писали свой длинный и сложный ответ, я выполнил шаги в другом ответе (так же, как вы добавили позже) и собирался принять его. Так что теперь у меня есть дилемма, ответ на который принять ... :) miroxlav 8 лет назад 0
Я предпочел бы иметь лучший ответ, чем первый ответ;) Если они одно и то же, то это бонус. Я действительно сообщил вам (в уже исправленном комментарии), что готовлю свой ответ. И я использую медленное подключение к интернету через мой мобильный телефон: / DavidPostill 8 лет назад 1
Ах да, ты сделал. OTOH, возможно, не стесняйтесь написать «вы можете включить ведение журнала аудита в локальных политиках», опубликовать и продолжить создание ответа с образовательной ценностью. Иногда даже небольшая подсказка могла бы помочь мне (ОП) лучше, чем ждать 60 минут для получения отличного ответа :) Я имею в виду, я знаю, где находятся местные политики, мне просто нужна была небольшая подсказка. miroxlav 8 лет назад 0
@DavidPostill: Было бы неплохо, если бы вы упомянули, как часто эти журналы очищаются (или как часто они должны очищаться вручную), потому что я думаю, что они могут быть довольно длинными ... Mehrdad 8 лет назад 0
@ Mehrdad Да, они могут стать большими. Журналы событий не очищаются автоматически. Насколько мне известно, невозможно удалить отдельные события из журнала, только удалить (очистить) полный журнал. И как часто они должны быть удалены вручную, основано на мнении: / DavidPostill 8 лет назад 0
@Mehrdad Журналы событий при необходимости могут быть удалены из командной строки с помощью `wevtutil`. Это проще, чем использовать графический интерфейс просмотра событий. DavidPostill 8 лет назад 1
3
Scott Chamberlain

The only way to see is you must have the audit enabled to track the creation of processes.

From the "Local Security Policy" program (Type secpol.msc from the run screen if you are having trouble finding it) go to "Security Settings -> Local Polices -> Audit Policy" then enable the "Audit process tracking" for "Success".

enter image description here

Once you do that go to the event viewer and check the "Secruity" event log, in there you will see "Audit Success" entries for every time a process is started or ended.

A process has exited. Subject: Security ID: SYSTEM Account Name: SCOTT-PC$ Account Domain: WORKGROUP Logon ID: 0x3E7 Process Information: Process ID: 0x1338 Process Name: C:\Windows\System32\consent.exe Exit Status: 0x0 

You will need to convert the Process ID you are looking for from decimal into hex (3336 becomes 0xD08). The easiest way to convert is open windows calculator, go to "Programmer" mode, enter the number in "dec" mode, then click on "hex" mode. The number displayed will be converted to hex for you.

Да, такой ответ я ожидал. Проще говоря: включите ведение журнала и, таким образом, сможете проверить его результаты. miroxlav 8 лет назад 0
0
mrTomahawk

If this is one time thing and you don't want to be always logging your processes, I would suggest using Microsoft Process Monitor (https://technet.microsoft.com/en-us/Library/bb896645.aspx). It needs to be ran before the popular is spawned, but even after the parent process is dead it will have captured all the information you were looking for.