NetUserChangePassword
을 호출하여 원격 컴퓨터의 암호를 변경하려고합니다. 컴퓨터에 로그인 할 때 암호를 변경할 수는 있지만 코드를 통해 암호를 변경할 수는 없습니다. 반환 값은 Password Being이 너무 짧음과 같은 2245입니다.원격 사용자 암호를 변경하는 방법이 필요합니다. NetUserChangePassword가 2245로 실패합니다.
나는이 링크를 읽었습니다 : http://support.microsoft.com/default.aspx?scid=kb;en-us;131226하지만 링크의 어떤 것도 나에게 도움이되지 못했습니다. (내 코드가 표시된 문제에 맞지 않습니다.)
이 오류를 수정하는 방법이나 원격 (Windows 2003) 컴퓨터에서 사용자 암호를 프로그래밍 방식으로 변경하는 다른 방법이 있다면 알려주십시오. 그것을 듣고 감사하게 생각하십시오.
Windows XP 컴퓨터에서 코드를 실행 중입니다.
여기에 현재 코드가 들어 있습니다. 도움이됩니다. (잘 작성된 사용자 코드를 보여줍니다.)
public partial class Form1 : Form
{
[DllImport("netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int NetUserAdd(
[MarshalAs(UnmanagedType.LPWStr)] string servername,
UInt32 level,
ref USER_INFO_1 userinfo,
out UInt32 parm_err);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USER_INFO_1
{
[MarshalAs(UnmanagedType.LPWStr)]
public string sUsername;
[MarshalAs(UnmanagedType.LPWStr)]
public string sPassword;
public uint uiPasswordAge;
public uint uiPriv;
[MarshalAs(UnmanagedType.LPWStr)]
public string sHome_Dir;
[MarshalAs(UnmanagedType.LPWStr)]
public string sComment;
public uint uiFlags;
[MarshalAs(UnmanagedType.LPWStr)]
public string sScript_Path;
}
[DllImport("netapi32.dll", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
static extern uint NetUserChangePassword(
[MarshalAs(UnmanagedType.LPWStr)] string domainname,
[MarshalAs(UnmanagedType.LPWStr)] string username,
[MarshalAs(UnmanagedType.LPWStr)] string oldpassword,
[MarshalAs(UnmanagedType.LPWStr)] string newpassword);
// Method to change a Password of a user on a remote machine.
private static uint ChangeUserPassword(string computer, string userName,
string oldPassword, string newPassword)
{
return NetUserChangePassword(computer, userName,
oldPassword, newPassword);
}
// Method used to create a new user on a Remote Machine
private static uint CreateUser(string computer, string userName,
string password)
{
const int UF_DONT_EXPIRE_PASSWD = 0x10000;
const int UF_ACCOUNTDISABLE = 0x000002;
const int USER_PRIV_GUEST = 0; // lmaccess.h:656
const int USER_PRIV_USER = 1; // lmaccess.h:657
const int USER_PRIV_ADMIN = 2; // lmaccess.h:658
USER_INFO_1 userinfo = new USER_INFO_1()
{
sComment = "Scan Track User",
sUsername = userName,
sPassword = password,
sHome_Dir = "",
sScript_Path = "",
uiPriv = USER_PRIV_USER,
uiFlags = UF_DONT_EXPIRE_PASSWD
};
uint output;
NetUserAdd(computer, 1, ref userinfo, out output);
return output;
}
private void button1_Click(object sender, EventArgs e)
{
string computer = "10.1.9.115";
string userName = "test2";
string psswrd = "ssssss";
string fullname = "";
uint output = CreateUser(computer, userName, psswrd);
MessageBox.Show(output.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
string computer = "10.1.9.115";
string userName = "test";
string oldPassword = "[email protected]!";
string newPassword = "!B3tt3r-Luck2";
uint result = ChangeUserPassword(computer, userName,
oldPassword, newPassword);
MessageBox.Show(result.ToString());
}
public Form1()
{
InitializeComponent();
}
}
그럴 수도 있다고 생각했습니다. 나는 그것을 완전히 독특하고 여전히 실패한 것으로 바꾸었다. (아이디어를 가져 주셔서 감사합니다). – Vaccano