use the FileSystemWatcher class to document the user who is making changes
Asked Answered
A

3

2

I have a console app that checks for changes occurring on the file system. I'm trying to find out if it's possible to get the username of the individual who is doing the changes?

Advancement answered 27/12, 2011 at 21:51 Comment(5)
This is not possible, all info about the process and its user account is lost by the time the file system sees the changes.Pinky
With some system-level module this might be possible but not with C# AFAIK.Intreat
@Advancement - There was a question asked a week or so ago where someone was trying to accomplish the same thing by reading the Windows audit log. I don't know that they ever got their answer but you might try following up with them. Here's a link to their question: #8620003Hexagon
Have you looked at something like SharePoint as @Darin confirm that its not possible to obtain who modified the document? SharePoint records who and can be setup to have version control + a whole bunch of other useful features.Washing
@Advancement Maybe you should think to implement a WEBDAV server, it is based on http and Windows(>XP) can see it as a share For ex., webdavsystem.com/serverMagyar
R
4

You'd be better off enabling auditing on the folder.

Right-click the folder, go to Properties > Security tab > Advanced > Auditing tab. There are options for recording an audit log of events that happen in that folder.

Raseta answered 27/12, 2011 at 22:0 Comment(1)
Unfortunately that would require me to have elevated permissions in order to access the Auditing tab.Advancement
V
0

No, it's not possible, the NTFS or FAT file system which is what Windows uses doesn't record this information. The best you could get about a file is last time it was changed.

Virendra answered 27/12, 2011 at 21:52 Comment(8)
Even if I am connected to a domain?Advancement
@MDL, a domain has nothing to do with how files are stored on a Windows OS which is NTFS or FAT which as I already stated in my answer doesn't record this information. Sorry. You can know when but not by whom.Virendra
The domain controller certainly doesn't have any idea about these changes. Could you imagine all of the extra metadata being passed around on a machine under even moderate load?Bronchia
@MDL, no, there isn't. Well, there isn't in the practical case. You could always write your own file system which records this information but talking from a practical standpoint, there isn't.Virendra
@Advancement That has nothing to do with the domain... it is just how the system works... the kernel knows obviously which process/user accesses/changes/writes a file but that information is not communicated to the filesystem... and it definitely is not communicated from the filesystem to filesystemwatcher...Intreat
@Advancement The only workaround is writing some kernel-level module which sits between any process accessing the filesystem and the kernel-side filesystem-code - it is possible but NOT from C# .Intreat
seen this question before and it's possible but he would have to look at implementing / using WMI as well as capturing or writing soem code to get the Domain User..Perdita
@Advancement ... or a filesystem filter driverFodder
J
0

You can't do this asynchronously with FileSystemWatcher, however you can do this synchronously using file system filter driver. The driver lets you get the user name of the account performing the operation.

Jequirity answered 28/12, 2011 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.