Every now and again, I come across an issue that takes up far more of my time than it should do… and, this afternoon, that’s exactly what happened so I’m posting the details here for anyone else in the same situation.
I’d installed a new copy of Windows in a virtual machine and, because it wasn’t domain-joined as part of the setup, the out of the box settings made me create a local user account that I didn’t need. After joining the domain and logging in as an administrator, I deleted the account and the profile, but was given a warning that not all files were removed. I checked and, sure enough, the folder for the account (called Mark) was still there in C:\Users. All of the usual attempts to remove it failed, regardless of what I did with permissions until I found a post on the My Digital Life blog, titled Delete Undeletable Files in Windows Vista. I was running Windows 7 but this advice for Vista sounded hopeful, so I ran the following commands against the folder that was causing me grief:
takeown /f foldername /r /d y
icacls foldername /grant administrators:F /t
(for files, I would not have needed the /r
switch on the takeown
command to recurse the folder structure.)
I was still having trouble deleting the folder from Windows Explorer; however these commands had given me the clue I needed (and answered why Explorer told me that the location was shared, but it didn’t show up in the list of shares…) – the AppData hidden folder was still there.
Using the command line, I navigated C:\Users\Mark\AppData and its two trees (Local and Roaming) to remove around 10 files and folders, after which I was able to successfully remove the C:\Users\Mark folder.
With that out of the way, I could log in with my domain account (also called Mark) and its profile was created at C:\Users\Mark instead of C:\Users\Mark.domainname.