The name 'ChangePassword' does not exist in the current context
I found this User class on the internet and am trying to use it in my app. The ChangePassword() function is declared as a public so I don't know why I can't call it.
namespace HelloWorld
{
public class User
{
[DllImport("Netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int NetUserChangePassword(
string domainname,
string username,
string oldpassword,
string newpassword
);
public static void ChangePassword(string username, string domain, string oldpassword, string newpassword)
{
int result = NetUserChangePassword(
domain,
username,
oldpassword,
newpassword
);
if (result != 0)
throw new Win32Exception();
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) // void means this function returns nothing
{
}
private void cmd_Set_Password_Click(object sender, EventArgs e)
{
ChangePassword(txt_Username.Text, txt_Domain.Text, txt_Old_Password.Text, txt_New_Password.Text);
}
}
}

New Topic/Question
Reply



MultiQuote





|