How do I change my win7 admin password?

rfresh

Active member
Joined
Aug 23, 2012
Messages
26
Programming Experience
1-3
I want to write a VS 2010 C# app that can set my admin password. My user account is Ralph and I am an Admin but I don't have a password set so I can boot up and get right to the desktop. However, that being said, I'd like to be able set a password for my account using C#.

Thanks for any help...
 
I'm asking about changing my password on my local win7 machine, not related changing my network password...(which I believe your link references?)...
 
No, it works fine for local user.
 
Hmmm...ok...thanks, but I'm using C# and that example is in C++. I'm new to C# so I am not able to convert C++ code to C#.
 
If you search web for NetUserChangePassword you should find Pinvoke.net high up in results, that place has many signatures, and possibly many other C# samples too.
 
Yeah...I have no idea what to do with this code. I'm new to C# but I know the sample code here is incomplete.

[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
);
 
That is a called a platform invoke signature. It is similar to when you declare a method signature of your own, but here you don't add the method body, it just routes the call to the defined Windows library. Anyway, you place it where you place methods in your code.
One thing you may be missing also is the namespace import, see pinvoke.net: FAQ (misc)
Calling the method is no different than calling any other method, be it your own methods, .Net library methods and so on. You write the name of the method you want to call and supply the parameter values.
 
Back
Top Bottom