为什么我得到未知错误1346? [英] Why I am getting unknown error 1346?

查看:134
本文介绍了为什么我得到未知错误1346?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我收到未知错误1346?



模拟代码后,我将从本地驱动器复制文件到网络驱动器时遇到异常1346。如果注释了相同的代码,则文件将被成功复制。我想在冒充之后做同样的事情。凭证和所有凭证都有效。



以下是我的代码:

  string  serverName = CheckUNCPath(  Z:); 
string username = @ Alexander.junior @ chn.nestgroup.net;

// string username =alexander.junior;
string password = [已删除] *;
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsIdentity identity = new WindowsIdentity(用户名,密码);
WindowsImpersonationContext context = identity.Impersonate();

string updir = serverName;
string destPath = @ D:\\ \\Alex_BackUp\Test\test1.txt;
File.Copy(destPath,updir, true );

解决方案

来自 https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385%28v= vs.85%29.aspx?f = 255& MSPPError = -2147217396 [ ^ ]



Quote:

ERROR_BAD_IMPERSONATION_LEVEL

1346(0x542)

要么假冒等级是未提供,或提供的模拟级别无效。





我知道您认为用户名和密码是正确的,但有些不对。也许他们没有足够的权限。也许用户名应该是domain \ username。不确定,但你必须在最后解决它。


如果我没记错,普通用户帐户不能冒充其他用户。管理员帐户可以。



您运行此代码的帐户必须拥有 SeImpersonatePrivilege 才能冒充其他人。要查看该帐户是否具有此权限,请打开CMD提示并输入:

 WHOAMI / PRIV 



你会得到这样的东西:

 Microsoft Windows [Version 10.0.10586] 
(c)2015 Microsoft Corporation。版权所有。

C:\ Users \XXXXXXXX> whoami / priv

特权信息
---------------- ------

特权名称描述州
============================ = ==================================== ========
SeShutdownPrivilege关闭系统已禁用
SeChangeNotifyPrivilege跳过遍历检查已启用
SeUndockPrivilege从扩展坞中删除计算机已禁用
SeIncreaseWorkingSetPrivilege增加进程工作集已禁用
SeTimeZonePrivilege更改时区已禁用

C:\ Users \XXXXXXXX>



如果您没有列出 SeImpersonatePrivilege ,则该帐户无法模仿其他人


Why I am getting unknown error 1346?

After the Impersonation code I am getting exception 1346 on copying file from a local drive to a network drive. If the same code is commented the file is getting copied successfully. I want to do the same after impersonation. The credentials and all are valid.

Below is my code:

 string serverName=CheckUNCPath("Z:");
 string username = @"Alexander.junior@chn.nestgroup.net";

  //string username = "alexander.junior";
  string password = "[removed]*";
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsIdentity identity = new WindowsIdentity(username, password);
WindowsImpersonationContext context = identity.Impersonate();

string updir = serverName;
string destPath = @"D:\Alex_BackUp\Test\test1.txt";
File.Copy(destPath,updir,true);

解决方案

From https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396[^]

Quote:

ERROR_BAD_IMPERSONATION_LEVEL
1346 (0x542)
Either a required impersonation level was not provided, or the provided impersonation level is invalid.



I know you think the username and password are correct, but something isn't right. Perhaps they don't have enough permissions. Perhaps username should be domain\username instead. Not sure, but you'll have to troubleshoot it on your end.


If I remember correctly, normal user account cannot impersonate other users. Administrator accounts can.

The account you're running this code under has to have the SeImpersonatePrivilege in order to impersonate someone else. To see if the account has this privilege, open a CMD prompt and type:

WHOAMI /PRIV


You'll get something like this:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\XXXXXXXX>whoami /priv

PRIVILEGES INFORMATION
----------------------

Privilege Name                Description                          State
============================= ==================================== ========
SeShutdownPrivilege           Shut down the system                 Disabled
SeChangeNotifyPrivilege       Bypass traverse checking             Enabled
SeUndockPrivilege             Remove computer from docking station Disabled
SeIncreaseWorkingSetPrivilege Increase a process working set       Disabled
SeTimeZonePrivilege           Change the time zone                 Disabled

C:\Users\XXXXXXXX>


If you don't have the SeImpersonatePrivilege listed the account cannot impersonate someone else.


这篇关于为什么我得到未知错误1346?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆