Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 278759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:17:21+00:00 2026-05-12T01:17:21+00:00

I am trying to call NetUserChangePassword to change the passwords on a remote computer.

  • 0

I am trying to call NetUserChangePassword to change the passwords on a remote computer. I am able to change the password when I log-in to the machine, but I can’t do it via code. The return value is 2245 which equates to the Password Being too short.

I read this link: http://support.microsoft.com/default.aspx?scid=kb;en-us;131226 but nothing in the link was helpful to me. (My code did not seem to fit any of the issues indicated.)

If you have any ideas how to fix this error or have a different way to programmatically change a users password on a remote (Windows 2003) machine I would be grateful to hear it.

I am running the code on a windows xp machine.

Here is my current code in-case it is helpful (Also shows my create user code which works just fine).

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 = "!B3tt3rLuck!@!";
        string newPassword = "!B3tt3r-Luck2";

        uint result = ChangeUserPassword(computer, userName, 
            oldPassword, newPassword);

        MessageBox.Show(result.ToString());
    }


    public Form1()
    {
        InitializeComponent();
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:17:22+00:00Added an answer on May 12, 2026 at 1:17 am

    Error 2245 could also be a password history problem. Is the new password one that was used in the recent past?

    Edit:
    It looks like this function broke after Server 2003 SP 2. I got the same error when calling the function from C++ using the example in the documentation. You’ll probably need to use NetUserSetInfo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call the WriteableBitmap.WritePixels method, but I can't seem to understand the
I am trying to call cleartool from an java application, but cleartool hangs even
I'm trying to call a stored procedure from my .NET code which has one
I'm trying to call the HttpServerUtuility.URLDecode function in C# using Visual Studio 2005, but
Trying to call a WCF with a netTcpBinding via Silverlight, I am getting the
Im trying to call some windows forms code (like setting label.visible = true in
In trying to call a method on the CodeMirror javascript code editor. I'm new
Im trying to call an external python script, and so far i was able
A consumer is trying to call my REST API from client-side code (Javascript /
Im trying to call python functions from C code, and i followed a sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.