远程删除 Windows 用户帐户 WCF 和 C# [英] Deleting Windows user accounts remotely WCF and C#

查看:24
本文介绍了远程删除 Windows 用户帐户 WCF 和 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 WCF(自托管)和 C# 以编程方式远程创建和删除 Windows 用户帐户吗?这在本地有效,但不能通过 WCF... 想法?

Can I programmatically and remotely create and delete Windows User accounts via WCF (self hosted) and C#? This works locally, but not via WCF... Ideas?

            DirectoryEntry localDirectory = new DirectoryEntry("WinNT://" + Environment.MachineName.ToString());
            DirectoryEntries users = localDirectory.Children;
            try
                {
                    DirectoryEntry user = users.Find(usernameAccount);
                    users.Remove(user);

                }catch(SystemException)
                {
                    System.Console.WriteLine("Error: User account not found in the system");
                }
            }

推荐答案

只要运行服务的凭据具有删除帐户的适当权限,它就应该可以工作.如果运行服务代码的默认凭据没有此类权限,您可能需要查看 冒充客户来做到这一点.

It should work, as long as the credentials with which the service is running have the appropriate permission to delete the account. If the default credentials in which the service code runs do not have such permission, you may want to look into impersonating the client to do that.

这篇关于远程删除 Windows 用户帐户 WCF 和 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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