{"id":3393,"date":"2013-08-27T07:00:00","date_gmt":"2013-08-27T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/08\/27\/how-can-i-find-out-which-process-and-user-is-modifying-a-file\/"},"modified":"2013-08-27T07:00:00","modified_gmt":"2013-08-27T07:00:00","slug":"how-can-i-find-out-which-process-and-user-is-modifying-a-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130827-00\/?p=3393","title":{"rendered":"How can I find out which process and user is modifying a file?"},"content":{"rendered":"<p>When troubleshooting a problem, you may discover that a file is being modified that shouldn&#8217;t, and you figure out would be nice if there were some way of finding out which process is modifying the file (so you can get it to stop).\n Enter the security auditing system.\n Every securable object has an associated system access control list (SACL) which controls what audit events are raised when a request is made to access the object. You can say, for example, &#8220;Log an event in the security event log if somebody tries to open this file for writing but is denied access,&#8221; or &#8220;Log an event in the security event log if somebody successfully creates a new file in this directory.&#8221;\n Here&#8217;s how it works. Let&#8217;s say that you want to access successful requests from any user to write to a particular file.\n View the Properties of the file, go to the Security tab, and click Advanced, then go to the Auditing tab and elevate to administrator if necessary.\n Next, click Add. What happens next depends on what version of Windows you&#8217;re using, since the interface varies slightly (but the basic idea remains the same). When asked for the security principal, set the Location to the local computer and use the object name <i>Everyone<\/i>.\n Older vesions of Windows will give you a grid of options. Look for the row corresponding to the operation you want to audit and check the box under <i>Successful<\/i> if you want to audit successful accesses or the box under <i>Failed<\/i> to audit failed accesses. (Or check both to audit both successful and failed accesses.) Repeat for each access you want to audit. In our case, we would check the <i>Create files \/ write data<\/i> and <i>Create folders \/ append data<\/i> boxes under the <i>Successful<\/i> column.\n Newer versions of Windows break the grid up into two questions. The first is whether you want to audit <i>Success<\/i>, <i>Fail<\/i>, or <i>All<\/i> access. In our case, we want to audit <i>Success<\/i>. The next question is what type of access you want to audit, and in our case we would check <i>Write<\/i>. (Or for finer control, click <i>Show advanced permissions<\/i> and check <i>Create files \/ write data<\/i> and <i>Create folders \/ append data<\/i>.)\n OK your way out of all the dialog boxes to save the changes.\n All right, let&#8217;s take this thing out for a spin. Open the file in Notepad, make some change, and then Save them. Now open the Event Viewer and go to the Security event log.\n And&#8230; no log entry.\n That&#8217;s because I forgot a step: You have to enable object access auditing.\n Open the Control Panel and look in the <i>Administrative Tools<\/i> folder. From there, you can run the <i>Local Security Policy<\/i> snap-in. If you are a command line nerd, you can run <tt>secpol.msc<\/tt>.\n Under <i>Local Policies<\/i>, <i>Audit Policy<\/i> set the <i>Audit object access<\/i> policy to enable global auditing of successful or failed accesses, depending on what you  need.\n Okay, let&#8217;s try it again. Modify the file and save it. Now go back to the security event viewer and you&#8217;ll see audit success events in your log. Again, depending on what version of Windows you&#8217;re using, the successful audit event will appear differently. For example, older versions of Windows might show<\/p>\n<table border=\"0\">\n<tr>\n<td valign=\"baseline\">\n<table border=\"0\">\n<tr>\n<td valign=\"baseline\">Event Type:<\/td>\n<td valign=\"baseline\">Success Audit<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Event Source:<\/td>\n<td valign=\"baseline\">Security<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Event Category:<\/td>\n<td valign=\"baseline\">Object Access<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Event ID:<\/td>\n<td valign=\"baseline\">567<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Date:<\/td>\n<td valign=\"baseline\">&#8230;<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Time:<\/td>\n<td valign=\"baseline\">&#8230;<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">User:<\/td>\n<td valign=\"baseline\">&#8230;<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Computer:<\/td>\n<td valign=\"baseline\">&#8230;<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Description:<\/td>\n<td valign=\"baseline\"><\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Object Access Attempt:<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\">\n<table border=\"0\">\n<tr>\n<td valign=\"baseline\">Object Server:<\/td>\n<td valign=\"baseline\">Security<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Handle ID:<\/td>\n<td valign=\"baseline\">208<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Object Type:<\/td>\n<td valign=\"baseline\">File<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Process ID:<\/td>\n<td valign=\"baseline\">1964<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Image File Name:<\/td>\n<td valign=\"baseline\">C:\\WINDOWS\\system32\\notepad.exe<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Access Mask:<\/td>\n<td valign=\"baseline\">WriteData (or AddFile)<br \/>             AppendData (or AddSubdirectory or CreatePipeInstance)<\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<\/table>\n<p> whereas newer versions might show<\/p>\n<table border=\"0\">\n<tr>\n<td valign=\"baseline\" colspan=\"3\">\n<table border=\"0\">\n<tr>\n<td valign=\"baseline\">Keywords:<\/td>\n<td valign=\"baseline\">Audit Success<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Date and Time:<\/td>\n<td valign=\"baseline\">&#8230;<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Source:<\/td>\n<td valign=\"baseline\">Microsoft Windows security auditing<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Event ID:<\/td>\n<td valign=\"baseline\">4663<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Task Category:<\/td>\n<td valign=\"baseline\">File System<\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\" colspan=\"3\">An attempt was made to access an object.<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\" colspan=\"3\">Subject:<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Security ID:<\/td>\n<td valign=\"baseline\">computer\\user<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Account Name:<\/td>\n<td valign=\"baseline\">user<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Account Domain:<\/td>\n<td valign=\"baseline\">computer<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Logon ID:<\/td>\n<td valign=\"baseline\">0x27ADB<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\" colspan=\"3\">Object:<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Object Server:<\/td>\n<td valign=\"baseline\">Security<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Object Type Name:<\/td>\n<td valign=\"baseline\">File<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Object Name:<\/td>\n<td valign=\"baseline\">C:\\test.txt<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Handle ID:<\/td>\n<td valign=\"baseline\">0x15c<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Resource Attributes:<\/td>\n<td valign=\"baseline\">S:AI<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\" colspan=\"3\">Process Information:<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Process ID:<\/td>\n<td valign=\"baseline\">0xdb0<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Process Name:<\/td>\n<td valign=\"baseline\">C:\\Windows\\System32\\notepad.exe<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\" colspan=\"3\">Access Request Information:<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Accesses:<\/td>\n<td valign=\"baseline\">WriteData (or AddFile)<br \/>         AppendData (or AddSubdirectory or CreatePipeInstance)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 2em\"><\/td>\n<td valign=\"baseline\">Access Mask:<\/td>\n<td valign=\"baseline\">0x6<\/td>\n<\/tr>\n<\/table>\n<p> Either way, you can see which process obtained write access to the file, running as what user, at what time.\n Newer versions of Windows include a bit more information in the event log entry to make it easier to find the access request you&#8217;re looking for as well as chase the access further. (For example, from the Logon ID, you can figure out which logon session modified the file.)\n This feature has been around since the beginning of Windows&nbsp;NT, but it seems that very few people know about it. Whenver I point it out to people, they say, &#8220;Hey, that&#8217;s cool. How long has that feature been there?&#8221;<\/p>\n<p> Now you too can look smart. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>When troubleshooting a problem, you may discover that a file is being modified that shouldn&#8217;t, and you figure out would be nice if there were some way of finding out which process is modifying the file (so you can get it to stop). Enter the security auditing system. Every securable object has an associated system [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-3393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>When troubleshooting a problem, you may discover that a file is being modified that shouldn&#8217;t, and you figure out would be nice if there were some way of finding out which process is modifying the file (so you can get it to stop). Enter the security auditing system. Every securable object has an associated system [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=3393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3393\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=3393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}