Reg add for loop

Deadly 提交于 2020-03-22 23:08:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!