本文介绍了从代码中的anywhare访问列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个获得NTFS权限的简单控制台代码





static void DumpSecurity(字符串路径)



{



FileSecurity sec = File.GetAccessControl(路径);



if(sec == null)

{

Console.WriteLine(找不到文件。);



返回;

};



foreach(sec.GetAccessRules中的FileSystemAccessRule规则(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());



};





};



我在尝试什么现在要做的就是在windowsForm应用程序中使用代码



添加了一个listBox和一个按钮



- 该功能由按钮事件触发

DumpSecurity(路径);



所以我的问题是我在DumpSecurity中看不到列表框()函数。换句话说,试图用
$ b替换



Console.WriteLine(bldr.ToString());

$ b listBox1.Items.Add(bldr.ToString());



如何在函数内部使列表框可访问(全局)?

非常感谢



我尝试过:



以编程方式在函数内创建一个列表框,而不是一个干净的解决方案

解决方案

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

解决方案


这篇关于从代码中的anywhare访问列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 15:26