问题
Sorry if this question has been asked before, but I haven't been able to find an answer I can understand and apply.
I'm writing a batch file that installs an application, and I need the batch file to add a registry key in the software key to every profile in the HKEY_USERS hive.
I've been able to use REG ADD to add the key to the currently logged on user, but because our help desk would be running this batch file from an elevated command prompt, that change would not affect the user who actually needs to run the application.
This is what I had for reg add
reg add "hkcu\software\application" /v "Current Practice" /t reg_sz /d "\\server\share"
Any suggestions?
回答1:
You need to load a user's hive into the registry before you can modify it:
@echo off
setlocal
set "hive=HKU\temp"
set "key=Software\application"
set "value=Current Practice"
set "data=\\server\share"
for /d %%u in (C:\Users\*) do (
if exist "%%~u\ntuser.dat" (
reg load %hive% "%%~u\ntuser.dat"
reg add "%hive%\%key%" /v "%value%" /t REG_SZ /d "%data%" /f
reg unload %hive%
)
)
来源:https://stackoverflow.com/questions/18324038/reg-add-for-loop