所谓离线,是指目的操作系统当前没有在运行,修改注册表是通过在其他系统上来访问目的操作系统的注册表文件来进行修改的过程
离线修改计算机注册表的好处:
- 出于维护的目的,目的操作系统可能出现问题,只能通过其他方式来修改注册表已达到修复目的操作系统
- 解除安全限制:如果进入目的操作系统,你可能需要输入帐号密码,另外有些注册表需要目的操作系统上有管理员权限才能进行修改,但是如果使用其他操作系统来离线访问目的操作系统注册表,便可以绕过限制
- 避免启动到目的操作系统,节省时间,比如说我在PE中使用ghost恢复了操作系统后,直接使用PE来离线修改恢复的计算机名称,那么这样可以避免一次重新启动,从而节省时间。
原理:
我们平常使用regedit来修改注册表,因此给大多数人的概念是注册表隐藏在系统中,没有办法像访问平常的文件一样进行访问,其实不然,注册表存储的数据也是以文件的方式放在磁盘上。
如果觉得想更多了解下注册表的信息,请访问我以前的日志,注册表的结构http://yoke88.spaces.live.com/blog/cns!E9D4B3DCE266C1B!550.entry
注册表存储数据存放在%systemroot%\system32\config 目录下,而用户的当前设定保存在用户配置目录下的ntuser.dat
xp系统下有6个文件
- system
- software
- sam
- security
- default
- BCD-Template (xp以后的机器上有,vista ,win7 ,win2008等)
- components (xp以后的机器上有,同上)
- Ntuser.dat
- system 对应HKLM\system
- software 对应HKLM\Software
- default 对应于HKEY_USERS 下的.default
- sam 对应hklm\sam
- security 对应hklm\security
- BCD-template 应该对应于hklm下的BCD00000000
- components 到现在还没有发现是挂载到哪里,知道的给评论下,这部分信息我的就算完整了
- ntuser.dat 对应HKCU
所以我们知道了registry的数据存放地点后就可以加载这些文件,然后用我们熟悉的regedit或者其他工具进行编辑
那么现在有两个问题:
- 如何加载和卸载redistry的数据文件到我们熟悉的regedit编辑器中?
- 如何更改加载后的注册表值?
加载可以使用regedit,选中HKLM或者HKEY_USERS节点,从文件菜单选择file—>load hive ,就会弹出对话框让选择注册表数据文件位置,选择完成后,会提示让你输入一个名称,那么我们要修改的离线数据表就都挂在该名称下。如下面我挂载其他操作系统的system 也就是其他操作系统注册表的HKLM\SYSTEM分支,我把它挂在了当前系统的HKLM\sys下,然后我直接操作HKLM\sys就相当于操作其他操作系统的HKLM\system
而卸载的时候我们只需要选择我们刚才挂在的节点名称,然后选择file –unload hive即可
也可使用命令行reg load 以及reg unload 来卸载,该命令的使用可以查看相关帮助,这个命令我们一般在自动化的工程中使用的到,后面我会给一个脚本,用来离线修改其他操作系统计算机名称的。
眼尖的同志可能注意到上面的HKLM\sys下只有controlset001 ,而没有controlset002,以及currentcontrolset ,如果您想了解为什么?请查看我前面的文章:
离线修改其他计算机的名称的脚本,这段代码在我的windows 2008上更改我的win7计算机名称成功。
Function LoadReg(ByVal RegDataPath,ByVal MountPath)
‘Mountpath like hku\mount1 or hklm\mount2
‘Return registry Mounted path
Dim objShell
Set objShell=CreateObject("wscript.shell")
objShell.Run "reg load """ & MountPath & """ """ & RegDataPath & """",0,True
Set objShell=Nothing
LoadRegFromFile=MountPath
End FunctionFunction UnloadReg(ByVal mountpath )
Dim objShell
Set objShell=CreateObject("wscript.shell")
objShell.Run "cmd /c reg unload """ & MountPath & """" ,0,True
Set objShell=Nothing
End FunctionFunction ModifyComputerNameOffline(byval MountPath,ByVal StrComputerName)
‘mountPath with be SYSTEM root key Mounted by loadreg function
If Len(mountpath) >0 Then
If Right(mountpath,1)="\" Then
mountpath=Left(mountpath,Len(mountpath)-1)
End If
mountpath=Replace(LCase(mountpath),"hklm\","HKLM\")
End If
Dim objshell,CurrentControlSetNumber
Dim RegPathSelectCurrent:RegPathSelectCurrent="\select\current"
Dim RegPathComputer:RegPathComputer="\Control\ComputerName\ComputerName"
Dim RegPathTCPIPPara:RegPathTCPIPPara="\Services\Tcpip\Parameters"
Set objshell=CreateObject("wscript.shell")
CurrentControlSetNumber=objshell.RegRead(mountpath & RegPathSelectCurrent)
RegPathComputer=mountpath & "\ControlSet00" & CurrentControlSetNumber & RegPathComputer
RegPathTCPIPPara=mountpath & "\ControlSet00" & CurrentControlSetNumber & RegPathTCPIPPara
objshell.RegWrite RegPathComputer & "\ComputerName",StrComputerName,"REG_SZ"
objshell.RegWrite RegPathTCPIPPara & "\NV Hostname",StrComputerName,"REG_SZ"
objshell.RegWrite RegPathTCPIPPara & "\Hostname",StrComputerName,"REG_SZ"
‘ WScript.Echo objshell.RegRead(RegPathComputer & "\ComputerName")
‘ WScript.Echo objshell.RegRead(RegPathTCPIPPara & "\NV Hostname")
‘ WScript.Echo objshell.RegRead(RegPathTCPIPPara & "\Hostname")
Set objshell=Nothing
End FunctionFunction newCompName(ByVal regSYSTEMFilePath,byval strNewCompname)
LoadReg regSYSTEMFilePath,"hklm\sys"
ModifyComputerNameOffline "hklm\sys",strNewCompname
UnloadReg("hklm\sys")
End Function
网上搜索追踪而来,原来博主才是这篇强文的作者。