开发者

How to change my DC password

开发者 https://www.devze.com 2023-04-13 02:54 出处:网络
I\'m logged in with my Windows 7 to the dom开发者_Go百科ain. I want to programmaticaly change my user\'s password.

I'm logged in with my Windows 7 to the dom开发者_Go百科ain.

I want to programmaticaly change my user's password.

I tried to do "net user /domain" But i've got Access denied error.

I don't want to change it manually (CTRL+ALT+DELETE, change password ...).

I'll be happy to get an answer in command line, python, c++ or c#.

Thanks,

Mattan


Not sure how to include it in C#, but there is Netapi32.dll library that incorporates the NetUserChangePassword function. http://msdn.microsoft.com/en-us/library/windows/desktop/aa370650%28v=vs.85%29.aspx

In python, there are two easy ways to do it. With ctypes you can include it by typing:

from ctypes.wintypes import windll
ChangePassword = windll.Netapi32.NetUserChangePassword

Then change the password by typing:

ChangePassword(domainname, username, oldpass, newpass)

"domainname" could be zero if you want to assign the password on current logon domain. However, if you already have windows tools for python istalled, then you could use win32net to change the password:

import win32net
win32net.NetUserChangePassword(domainname, username, oldpass, newpass)

Again, 0 can be used instead of domain name.


You can use the simple VB script (named changepass.vbs):

Dim UserDomain
Dim UserName
Dim NewPassword

UserDomain = WScript.Arguments.Item(0)
UserName = WScript.Arguments.Item(1)
NewPassword = WScript.Arguments.Item(2)

Set User = GetObject("WinNT://"& UserDomain &"/"& UserName & "")

Call User.SetPassword(NewPassword)
If err.number = 0 Then
    Wscript.Echo "The password change was successful."
Else
    Wscript.Echo "The password change failed!"
End if

It accepts 3 parameters: domain name, user name and a new password. The current user must have permissions to change the password. If you want to change password on the local computer provide "." as a domain name. Example:

cscript changepass.vbs "YOUR_DOMAIN" "user1" "qw23442q"
0

精彩评论

暂无评论...
验证码 换一张
取 消