我需要用python3打开一个注册表配置单元文件。这应该可以在windows系统上实时工作,也可以使用从另一个系统复制的配置单元文件。
不幸的是,我无法用python打开甚至看不到文件:
# !/usr/bin/env python3
import os.path
import os
hive_dir = os.path.join(os.path.expandvars(r"%SystemRoot%"), "System32", "Config")
HIVES = ["System", "San", "Security", "Software", "Ntuser.dat"]
def main():
print("Hive directory {} exists: {}".format(hive_dir, os.path.exists(hive_dir)))
print("Content of {}: {}".format(hive_dir, os.listdir(hive_dir)))
for hive in HIVES:
hive_path = os.path.join(hive_dir, hive)
print("{} exists: {}".format(hive_path, os.path.exists(hive_path)))
if __name__ == '__main__':
main()
脚本首先检查配置单元文件应该位于的目录,以及文件是否确实存在。输出为:
Hive directory C:\WINDOWS\System32\Config exists: True
Content of C:\WINDOWS\System32\Config: ['Journal', 'RegBack', 'systemprofile', 'TxR']
C:\WINDOWS\System32\Config\System exists: False
C:\WINDOWS\System32\Config\San exists: False
C:\WINDOWS\System32\Config\Security exists: False
C:\WINDOWS\System32\Config\Software exists: False
C:\WINDOWS\System32\Config\Ntuser.dat exists: False
根据MicrosoftsMSDN文档,文件应该在那里,在WindowsExplorer中打开目录确实会显示文件。
使用powershell,我还可以验证文件是否已就位:
PS C:\Users\test> dir "$env:SystemRoot\System32\Config"
Verzeichnis: C:\WINDOWS\System32\Config
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 05.12.2016 13:38 bbimigrate
d----- 16.07.2016 13:47 Journal
d----- 14.03.2017 10:19 RegBack
d----- 05.12.2016 13:19 systemprofile
d----- 16.03.2017 10:14 TxR
-a---- 16.03.2017 10:16 1048576 BBI
-a---- 05.12.2016 13:15 28672 BCD-Template
-a---- 20.03.2017 09:32 91488256 COMPONENTS
-a---- 16.03.2017 10:16 1572864 DEFAULT
-a---- 16.03.2017 12:16 5259264 DRIVERS
-a---- 05.12.2016 14:02 32768 ELAM
-a---- 20.03.2017 09:22 120 netlogon.ftl
-a---- 05.12.2016 13:12 73728 SAM
-a---- 16.03.2017 10:16 73728 SECURITY
-a---- 16.03.2017 10:16 103022592 SOFTWARE
-a---- 16.03.2017 10:16 19136512 SYSTEM
-a---- 05.12.2016 12:39 8192 userdiff
-a---- 16.07.2016 13:45 4096 VSMIDK
PS C:\Users\test> Test-Path "$env:SystemRoot\System32\Config\SECURITY"
True
我运行的是64位windows10enterprise和python3.5。我在我的生产系统和虚拟机上验证了行为。以管理员身份运行python并没有改变任何事情。
这里怎么了?
1条答案
按热度按时间zzlelutf1#
您正在运行32位python
SysWOW64\config
由于wow64文件系统重定向。在64位windows上运行的32位进程可以访问本机系统目录"%SystemRoot%\SysNative"
. 这个目录是虚拟的,在本机进程中不存在,所以首先检查它是否存在。“san”也是一个拼写错误;应该是“山姆”。系统配置目录中不应该有“ntuser.dat”。该文件仅存在于用户配置文件目录中。