Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Is there any way to do modify the HKEY_CURRENT_USER on a mapped drive connected by USB or BartPE? I have admin access and know the user/profile name and need to modify HKCU for one profile only from a bat file...Thanx!

Not easily, no; there's just no clean way to pick the current user you actually care about. You would have to walk HKU and focus on whom you don't want.
Now if you want to modify a user's profile when they're not logged on, then that's probably far too easy to do.
All further inquires should be directed towards the Programming forum, where the people are all too eager to show off their batch file skills.

This was my first post here. I will redirect my request as you suggest. However, you hit the nail on the head. I will be logged on the system drive and use a .bat file to clean profile on another drive. I need to be able to connect the other drive to my PC, and run .bat file. It works except I also want to clear MRUs for specific profile. If easy, please provide sample. Otherwise I'll goto prg area. Thanx either way!

No you didn't; it was moved.
The command you're looking for is:
REG LOAD HKU\OpenUser "<path to the user's profile path>\ntuser.dat"
<do whatever REG commands you want>
REG UNLOAD HKU\OpenUser

The REG commands you want to run will probably look something like this:
for /f "delims=" %%a in ('reg query hku\OpenUser\Software /s ^| findstr /i "^HKEY.*MRU"') do reg delete %%a /fBut I do suggest backing up ntuser.dat before attempting it.

I tried this in response to your response above - #4:
REG LOAD HKU\OpenUser "C:\Documents and Settings\%USERNAME%\ntuser.dat"
[-HKEY_USERS\OpenUser\Software\Microsoft\Windows\CurrentVersion\Explorer \RecentDocs]
REG UNLOAD HKU\OpenUserI received the following message after the "REG LOAD" and "REG UNLOAD" lines:
"The operation completed successfully"
I received the following message after the "HKU_USERS" line:
"The system cannot find the path specified"
Any ideas on what is wrong with my path? Thanks...

Yeah, CMD doesn't accept [-KEY] commands; it's a batch file, not a registry script. Try:
REG DELETE HKU\OpenUser\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs /va /f

Making progress. I received "success" messages on Lines #1, 2, and 6 below. I received "invalid parameter" mesaages on lines #3 and 4. I received "Can't find key or value" message on line #5. I have tried various combinations of parameters. I even tried a load and unload statement for each deletion.

I guess it would help if I include the code:
REG LOAD HKU\OpenUser "C:\Documents and Settings\%USRPROFILE%\ntuser.dat"
REG DELETE HKU\OpenUser\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs /va /f
REG DELETE HKU\OpenUser\Software\Microsoft\Internet Explorer\TypedURLs /f
REG DELETE HKU\OpenUser\Software\Microsoft\Internet Explorer\TypedURLs
REG DELETE HKU\OpenUser\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /f
REG UNLOAD HKU\OpenUser

Actually, if you're running the script on the current user, then you can use HKCU instead of loading it as OpenUser.
Lines 3 and 4 are complaining because you don't have quotes around the registry path. You need them because of the space in "Internet Explorer." Also, they're the same line, repeated.
Line 5 is complaining because, well, the key doesn't exist. You'll notice it stops complaining for one run if you open and close regedit, which recreates the key.
Updated script:
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs /va /f
REG DELETE "HKCU\Software\Microsoft\Internet Explorer\TypedURLs" /va /f
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /fEdit: Doesn't %UserProfile% already include the C:\Documents and Settings?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |