Windows: 定制多用户多Registry键脚本

关键就在这个字。

先看看单一Registry键的定制过程:

reg load HKU\TempHive C:\Users\Default\NTUSER.dat
reg import Sample.reg
reg unload HKU\TempHive

下面的脚本可以处理用于Default用户的多个reg文件

REG load HKU\TempHive "C:\Users\Default\NTUSER.DAT" > nul
for /F "delims=*" %%i in ('dir /A /B *.reg') do REG import "%%i" >nul
REG unload HKU\TempHive >nul

下面是处理多用户的多个reg文件

for /F "delims=*" %%i in ('dir /A /B %SystemDrive%\Users') do CALL :ModUserRegs "%%i" TempRegs > nul
goto End


:ModUserRegs
   IF "%USERNAME%" == "%~1" (
      Echo  %1 is Current user.
   ) ELSE (
      IF EXIST "%SystemDrive%\Users\%~1\NTUSER.DAT" (
         REG load HKU\TempHive "%SystemDrive%\Users\%~1\NTUSER.DAT" > nul
         for /F "delims=*" %%i in ('dir /A /B ^"%~d0%~p0TempRegs\*.reg^"') do REG import "%~2\%%i" >nul
         REG unload HKU\TempHive >nul
         Echo  %1 is done.
      ) ELSE (
         Echo  %1 isn't a user.
      )
   )
goto :eof

最后, 下面是完整的带有日志记录功能的batch脚本:

ECHO OFF

:: ---------------------------------------------------------------------------------------
:: Modify All and Default User Registry
:: Version: 1.1
:: Copyright Tony Liu, 2012
::
:: History:
::    Initial: May 22, 2012 Tony Liu
::
:: Description: It imports all defined registry into all system users NTUSER.DAT registry hive including Default User.
::
:: How TO:
::    Put exported registry files, .reg files, in TempRegs folder and change all the [HKEY_CURRENT_USER] root to [HKEY_USERS\TempHive] in .reg files.
:: ---------------------------------------------------------------------------------------

Echo ---------------------------------------------------------------------------- >> History.log
Echo : Modify All and Default User Registry : >> History.log
Echo : Start: %time%, %date% >> History.log
Echo : Windows Version:  >> History.log
systeminfo | find "OS Name" | find "Windows 7" >> History.log
if %ERRORLEVEL% NEQ 0 goto End
IF Not Exist TempRegs (
   Echo Error: .\TempRegs folder not exist. >> History.log
   goto End
)

:: for /F "delims=," %%i IN (UserList.txt) do echo "%%i"
for /F "delims=*" %%i in ('dir /A /B %SystemDrive%\Users') do CALL :ModUserRegs "%%i" TempRegs > nul
goto End


:ModUserRegs
   IF "%USERNAME%" == "%~1" (
      Echo  %1 is Current user. >> History.log
   ) ELSE (
      IF EXIST "%SystemDrive%\Users\%~1\NTUSER.DAT" (
         REG load HKU\TempHive "%SystemDrive%\Users\%~1\NTUSER.DAT" > nul
::         for /F "delims=*" %%i in ('dir /A /B ^"%~d0%~p0TempRegs\*.reg^"') do REG import "%~2\%%i" >nul
         REG unload HKU\TempHive >nul
         Echo  %1 is done. >> History.log
      ) ELSE (
         Echo  %1 isn't a user. >> History.log
      )
   )
goto :eof


:End
Echo : End: %time%, %date% >> History.log
Echo ---------------------------------------------------------------------------- >> History.log
goto :eof

你可能感兴趣的:(windows)