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

推荐订阅源

U
Unit 42
T
Threatpost
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
Project Zero
Project Zero
H
Heimdal Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
S
Securelist
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
NISL@THU
NISL@THU
N
News and Events Feed by Topic
S
Security Affairs
The Last Watchdog
The Last Watchdog
T
Tor Project blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security

博客园 - 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