I know there are other topics on here with an identical goal, but don't think there's one in batch file format so here goes :
I've done a simple reg query in a batch , to find the registry key containing a user profile.
set /p username= please enter the user name ?
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /f "C:\users\%username%" /d /s /e
this finds the exact key I'm looking for which is
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-1908996837-4138030977-3423296585-49875
I then want to delete that key and all that is in it, but the output of the reg query command is actually giving 3 different results, which is making it difficult for me to use in a for loop.
Here's what it actually outputs to a text file
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-1908996837-4138030977-3423296585-49875
ProfileImagePath REG_EXPAND_SZ C:\Users\Mr Smith
End of search: 1 match(es) found.
So the next line I have is a for loop which obviously, based on the output of the above command, is not quite doing what I want
for /F %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /f "C:\users\%username%" /d /s /e') do reg delete %%a /f
So the ultimate aim being to perform this
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-1908996837-4138030977-3423296585-49875" /va /f
but obviously without knowing the and typing in the full key name
Thanks
%username%
. That's a reserved variable containing the username of the current logged on user. Next, this sort of thing makes me nervous. You're going to be leaving a bunch of orphaned profiles in HKU and directories in C:\Users. It's best to use the dialog resulting fromrundll32.exe sysdm.cpl,EditUserProfiles
to delete user profiles. – rojo