无法通过C#模拟域用户

时间:2013-08-20 10:19:24

标签: c#

我正在尝试模仿远程管理员用户,以便我可以对远程Linux机器上的文件执行修改。但是我收到错误消息,因为拒绝访问路径。 然而,我可以通过putty使用命令手动执行此操作:

sudo -S -u wtsnqa rm /path-to-file/

任何帮助都值得一看。

我的代码:

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "sj1slm612",
    UserName = "userid",
    Password = "password",
    SshHostKeyFingerprint = "ssh-rsa 2048 fa:e9:58:24:1b:41:a3:15:63:0d:c0:72:41:5d:51:7a"
};

using (Session session = new Session())
{
    // Connect
    session.Open(sessionOptions);

    // Performing removing files from remote server via impersonation.......

    AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
    using (WindowsIdentity Authorized_user = new WindowsIdentity("wtsnqa"))
    {
        using (WindowsImpersonationContext context = Authorized_user.Impersonate())
        {              

            File.Delete(@"\\sj1slm612\apps\instances\express_13000\configuration\standalone-full.xml");
            File.Delete(@"\\sj1slm612\apps\instances\query_13100\configuration\standalone-full.xml");
            File.Delete(@"\\sj1slm612\apps\instances\wppapi_13200\configuration\standalone-full.xml");
            File.Delete(@"\\sj1slm612\apps\instances\wppgui_13300\configuration\standalone-full.xml");

            Console.WriteLine("All config files removed from sj1slm612");
            Console.ReadLine();
            context.Undo();
        }

0 个答案:

没有答案