惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
I
InfoQ
The Register - Security
The Register - Security
L
LangChain Blog
H
Help Net Security
The GitHub Blog
The GitHub Blog
S
Schneier on Security
博客园 - 【当耐特】
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
The Cloudflare Blog
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
雷峰网
雷峰网
N
Netflix TechBlog - Medium
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - 聂微东
PCI Perspectives
PCI Perspectives
Last Week in AI
Last Week in AI
A
Arctic Wolf
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
S
Secure Thoughts
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
SecWiki News
SecWiki News
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
Schneier on Security
Schneier on Security
P
Proofpoint News Feed
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AI
AI
Engineering at Meta
Engineering at Meta

博客园 - db's jim

NuGet 无法连接到远程服务器-解决方法(转) 未能解析此远程名称:’nuget.org’ 解决方法(转) [转]jquery对事件冒泡的处理方法 Asp.net中的认证与授权 JS的事件监听机制 用映射的方法获取当前方法的名称 log4net的各种Appender配置示例(转) System.Diagnostics命名空间里的Debug类和Trace类的用途(收藏) Newtonsoft.Json处理日期问题 Failed to execute request because the App-Domain could not be created C#Windows服务程序安装 VS2010快捷键 生成方法存根 (Stub) NHibernate 事务查询的更新事件 Nhibernate.hbm2ddl.auto配置详解 NHibernate.Tool.hbm2ddl SchemaExport SQL2005 开窗函数 将EXCEL文档导入SQL server 2005错误 castle ActiveRecord 初始化
通过WEB方式修改windows帐号的秘密
db's jim · 2011-10-01 · via 博客园 - db's jim

因为项目的要求,要做一个WEB service,通过传入用户名和新的密码,更新Windows帐号的密码,代码入下:

[WebMethod]
public bool ChangePassword(string userName,string password,string validCode)
{
string msg = "";

if (validCode != getOriginValidCode())
{
msg = "无效的BI确认码!";
throw new Exception(msg);
;
}

string adPwd = System.Configuration.ConfigurationManager.AppSettings["adPwd"];
string adUser = System.Configuration.ConfigurationManager.AppSettings["adUser"];

DirectoryEntry myDirectoryEntry;
myDirectoryEntry = new DirectoryEntry("WinNT://" + Environment.MachineName, adUser, adPwd);

DirectoryEntry u = myDirectoryEntry.Children.Find(userName);
if (null == u)
{
msg = "无效的用户";
throw new Exception(msg);
}

u.Invoke("setPassword", password);
u.CommitChanges();

if (msg != "")
{
throw new Exception(msg);
}

return true;
}

运行是发现有错误:

u.Invoke("setPassword", password);

一般性拒绝访问错误

我估计是权限的问题,在事件查看器里看了下,发现是以NT AUTHORITY\NETWORK SERVICE来执行操作的,导致权限不足,修改web.config文件,添加以下两行后解决:
<authentication mode="Windows"/>
<identity impersonate="true" userName="userName" password="password"/>

类型的技术文章:
http://www.cnblogs.com/Anper/archive/2009/03/24/1420405.html