I am trying to programmatically delete windows accounts along with their corresponding folders under c:\Users in windows 2008R2.
I call net user [user name] /delete command in the program but it does not delete the folder “user name” under c:\users. The DelectFile function does not work: error code is 5.
Is there a way to solve it?
You can’t just DeleteFile a directory. You have to explicitly iterate through the contents of the directory, deleting each file and removing each subdirectory.
Also, be warned that the name of the user profile folder is not always identical to the username. The mapping is stored in the registry somewhere.