Tag: 模仿

模拟管理员帐户以编辑注册表项不起作用(C#)

我使用以下代码编辑本地计算机配置单元中的注册表项(’SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList \%SID%’)。 在我真正尝试打开注册表项(具有写权限)之前,一切似乎都没有问题; 抛出SecurityException,并显示消息“不允许请求的注册表访问”。 我已经检查并重新检查了注册表项和我冒充的用户的权限,并且全部检出。 登录到模拟用户的帐户时,代码运行正常,但是当以受限用户身份登录时,代码会失败。 这就像模仿一样,除了给予线程管理权限。 任何关于如何解决这个问题的想法将不胜感激! string KEY_STR = “SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\” + WindowsIdentity.GetCurrent().User.Value; WindowsImpersonationContext adminContext = null; IntPtr tokenHandle = new IntPtr(0); try { LogonUser(userName, domainName, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle); if (tokenHandle.Equals(new IntPtr(0))) LogonUser(userName, computerName, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle); WindowsIdentity adminIdentity = […]

LogonUser和委托

我正在使用LogonUser win32 api: token = LogonUser(…) WindowsIdentity newId = new WindowsIdentity(token); WindowsImpersonationContext impersonatedUser = newId.Impersonate(); 但是,在此之后调用WCF服务时,我无法使用模拟身份。 我认为这是因为impersonatedUser.ImpersonationLevel等于模拟。 这是什么原因? 是ImpersonationLevel.Identification的级别我需要什么? 如何获得这样的水平?

当dns或netbios不可用时,如何通过网络模拟用户的文件副本

可能重复: 在C#中访问Windows中受密码保护的网络驱动器? 我在DomainA上运行ComputerA作为userA需要将一个非常大的文件复制到WorkgroupB上的ComputerB,其中ip为192.168.10.2到只有userB具有写访问权限的Windows共享。 没有netbios或dns解析因此计算机必须由IP引用 我先试试 AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal); WindowsIdentity UserB = new WindowsIdentity(“192.168.10.2\\UserB”, “PasswordB”); //Execption WindowsImpersonationContext contex = UserB.Impersonate() File.Copy(@”d:\bigfile”, @”\\192.168.10.2\bifgile”); contex.Undo(); 但我得到一个System.Security.SecurityException “提供的名称不是一个正确形成的帐户名称。” 所以我试过了 AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal); WindowsIdentity webinfinty = new WindowsIdentity(“ComputerB\\UserB”, “PasswordB”); //Execption 但我得到“登录失败:未知的用户名或密码错误。” 而错误。 所以我试过 IntPtr token; bool succeded = LogonUser(“UserB”, “192.168.10.2”, “PasswordB”, LogonTypes.Network, LogonProviders.Default, out token); if (!succeded) { throw new Win32Exception(Marshal.GetLastWin32Error()); } WindowsImpersonationContext contex […]

在其他用户和域下打开共享文件?

我有一个C#控制台应用程序需要读取另一个域中的计算机上的共享文件。 当应用程序尝试访问该文件时,由于本地用户无权访问共享资源,因此会发生exception。 目前我通过从运行中打开共享文件夹手动克服此问题,并将用户名和密码放入Windows身份validation对话框,然后运行该应用程序。 我怎么能以编程方式做到这一点?