I found a simple console code that gets the NTFS permissions
static void DumpSecurity(string path)
{
FileSecurity sec = File.GetAccessControl(path);
if (sec == null)
{
Console.WriteLine("File not found.");
return;
};
foreach (FileSystemAccessRule rule in sec.GetAccessRules(true, true, typeof(NTAccount)))
{
StringBuilder bldr = new StringBuilder();
if (rule.AccessControlType == AccessControlType.Deny)
bldr.Append("[DENY] ");
if (rule.IsInherited)
bldr.Append("[INHERITED] ");
bldr.AppendFormat("{0} ", rule.IdentityReference);
bldr.Append(rule.FileSystemRights);
Console.WriteLine(bldr.ToString());
};
};
What I am trying to do now is to use the code in a windowsForm application
added a listBox and a button
-The function is triggered by a button event
DumpSecurity(path);
so my problem is I cannot see the listbox within the DumpSecurity() function. In other words, trying to replace the
Console.WriteLine(bldr.ToString());
by
listBox1.Items.Add(bldr.ToString());
how can I make the listbox accessible (global) inside the function?
many thanks
What I have tried:
programmatically create a listbox inside the function, not a clean solution