如何present凭据才能打开文件?凭据、才能、文件、present

由网友(黑色童话、我为谁颠覆世界)分享简介:我如何指定以用户名和密码,我的程序打开一个文件进行读取?需要访问该文件的程序是从一个帐户运行没有读访问该文件的文件夹。程序是用C#和.NET 2,运行在XP和文件是Windows Server 2003的计算机。How do I specify the username and password in ord...

我如何指定以用户名和密码,我的程序打开 一个文件进行读取? 需要访问该文件的程序是从一个帐户运行 没有读访问该文件的文件夹。 程序是用C#和.NET 2,运行在XP和文件是Windows Server 2003的计算机。

How do I specify the username and password in order for my program to open a file for reading? The program that needs to access the file is running from an account that does not have read access to the folder the file is in. Program is written in C# and .NET 2, running under XP and file is on a Windows Server 2003 machine.

推荐答案

您想冒充谁不具有访问该文件的权限的用户。

You want to impersonate a user who does have the rights to access the file.

我建议使用一类这样的 - http://www.$c$cproject.com/KB/cs/zetaimpersonator.aspx.它隐藏了所有讨厌的实施做模拟的。

I recommend using a class like this - http://www.codeproject.com/KB/cs/zetaimpersonator.aspx. It hides all the nasty implementation of doing impersonation.

using (new Impersonator("myUsername", "myDomainname", "myPassword"))
{
  string fileText = File.ReadAllText("c:test.txt");
  Console.WriteLine(fileText);
}
阅读全文

相关推荐

最新文章