NetChangePassword( string servername, string username, string password ) { uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS; if (String.IsNullOrEmpty(servername)) { servername = null; } if (String.IsNullOrEmpty(username)) { username = null; } if (String.IsNullOrEmpty(password)) { password = null; } USER_INFO_1003 ui1003 = new USER_INFO_1003(); ui1003.usri1003_password = password; IntPtr bufptr = Marshal.AllocHGlobal(Marshal.SizeOf(ui1003)); try { if (!NetApiInitCalled) { result = NetApiInit(); if (result != (uint)LUGAPI.WinError.ERROR_SUCCESS) { return result; } NetApiInitCalled = true; } Marshal.StructureToPtr(ui1003, bufptr, false); result = (uint)NetUserSetInfo(servername, username, 1003, bufptr, IntPtr.Zero); } catch (Exception) { result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE; } finally { Marshal.DestroyStructure(bufptr, ui1003.GetType()); Marshal.FreeHGlobal(bufptr); } return result; }