Find out which process accesses a file
Sometimes is necessary to find out which process accesses, alters or deletes a specific file. Various auditing tools may be used for this purpose. This article describes Process Monitor ( procmon ) - one of publicly available tools for MS Windows.
Running procmon can cause extensive load. Also the output file can be quite large, so it is important to run the tool only for a necessary time frame, not much longer.
To capture details about access to specific file proceed as follows:
Download process monitor utility athttp://technet.microsoft.com/en-us/sysinternals/bb896645
Run "procmon.exe"
In case the window "Process Monitor Filter" occurs, click "OK"
Choose the destination of trace file
Go to File > Backing Files
Select option "Use file named:"
Fill in preferred path for the temporary logging file, for example "C:\test\procmonlog.PML"
Click OK twice
Close "procmon.exe" and start it again for the changes to take effect
From now on, events related to operations with files (but also registry etc.) are recorded
Setting up destination of a trace file is optional. However it may help to prevent exhausting the virtual memory in a long running captures.
Set up a filter
If you know exactly what you are looking for, you may set up the filter
Go to Filter > Filter... > press Reset > specify the filter > press Add > press OK
Example:
Path Contains locations.configGo to Filter > click Drop Filtered Events
Clear the capture file
Go to Edit > click Clear Display
Reproduce the issue and save the output
The first option - when issue can be reproduced on demand at any time
Reproduce the issue
Stop the capturing
Go to File > click Capture Events
Store the output
Go to File > Save
select "Events displayed using current filter"
choose format "Native Process Monitor Format (PML)"
choose Pathclick OK
The second option - when the issue occurs only just after the computer restart
Enable logging on restart
Go to Options > Click Enable Boot logging > click OK
Close Procmon
Restart the computer and wait for issue to occur
Imagine that you were trying to catch the situation where FlexiSpooler service fails to start. For that purpose you could repeatedly review the Windows System Event logs via PowerShell command as this one and wait for the error:
Get-WinEvent -FilterHashtable @{logname='system';StartTime=(Get-Date).AddHours(-1)} | Where-Object {( $_.Id -match "60\d\d" -or $_.Message -like '*YSoftSQ-FSP*' -or $_.Message -like '*YSoft SafeQ FlexiSpooler*' )} | Sort-Object TimeCreated -Descending | Format-Table -Property TimeCreated, Id, LevelDisplayName, Message -AutoSize
Once the issue occurs
run Procmon again
Confirm the filters by OK (make no changes)
Click YES to save data captured on server start > save the PML file
Note: The PML file generated this way will contain events from the server startup till the point when you started the Procmon.exe.
The example below demonstrates a situation where FlexiSpoolerService.exe was unable to locate file locations.config. Later the file was manually created via notepad.exe and since then the file detection and its reading was a success.
