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?
use the FileSystemWatcher class to document the user who is making changes
Asked Answered
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.
Unfortunately that would require me to have elevated permissions in order to access the Auditing tab. –
Advancement
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.
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 driver –
Fodder
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.
© 2022 - 2024 — McMap. All rights reserved.
share
For ex., webdavsystem.com/server – Magyar