Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am using the following code to change the administrator password from the guest account with administrative right and it always returns 5.when i am trying to change the password of guest account from administrator it works good.any idea on this????


C++
USER_INFO_1003  pi1003;
NET_API_STATUS  nas;
LPCWSTR username = L"Administrator";
pi1003.usri1003_password = (WCHAR *)L"ABC123";
DWORD foo;

char buffer[500];

wcstombs(buffer, username, 500);
//MessageBox(buffer);


nas = NetUserSetInfo(
               NULL,  // computer name
               username,      // username
               1003,           // info level
               (LPBYTE)&pi1003,     // new info
               &foo
               );
Posted
Updated 16-Jan-16 13:45pm
v5
Comments
Jochen Arndt 16-Jan-16 7:29am    
Error 5 is 'Access denied' which is obvious:
You can not set the administrator password when logged in as guest. You must be logged in as administrator.

The password of any account can be changed only be the user itself and the administrator.
Member 11648410 18-Jan-16 6:27am    
Jochen Arndt whereto look up into the error codes.i have searched the header file but did not find the error codes
Jochen Arndt 18-Jan-16 6:33am    
Most error codes - including this - are defined in WinError.h which is located in the platform SDK include directory.

1 solution

STOP. Just THINK about what you said for a second:
Quote:
I am using the following code to change the administrator password from the guest account


How secure do you think a system would be if you could allow a guest or user account to change the password on an Admin account? It doesn't matter what reason you have stuck in your head to justify doing this.

You will NEVER be able to reset the password on an Admin account from anything other that another Admin account.
 
Share this answer
 
Comments
Member 11648410 16-Jan-16 19:43pm    
Dave Kreskowiak. thank you for posting a solution to my query, Its a client requirement and i conveyed client the same words which you have written long back.Just i was searching for the last possible solution(if any).
Dave Kreskowiak 16-Jan-16 23:02pm    
Just because a client said it does not make it a requirement. Customers rarely have a clue about what they want or why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900