假设 Net 进程 P
在 Windows 帐户 A1
下运行。我假设如果线程(在 P
中运行)在除 A1
之外的其他身份(通过 Thread.CurrentPrincipal.Identity
获得)下运行,它仍然访问系统资源(如文件等)时是否具有与A1
相同的权限?
谢谢
最佳答案
我不希望具有不同身份的线程从进程身份“继承”权限。
只是为了确保我运行了模拟测试。使用此处的示例 WindowsIdentity.Impersonate我在不同的线程上运行了以下代码。
WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
Thread.CurrentPrincipal = new WindowsPrincipal(newId);
string foo = System.IO.File.ReadAllText (@"test.txt");
Console.WriteLine(foo);
即使进程的 ID 有权读取 test.txt,如果 newID 没有权限,它也会失败。
关于.net - 线程的身份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4608455/