创建注册表项 SID REG_BINARY

Creating Registry keys SID REG_BINARY

我正在通过 PowerShell 创建一个新的本地帐户并在

中创建他们的配置文件
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\

也是。

我可以通过以下方式获取用户的 SID; ([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value

但是,在用户的 SID 密钥中,有一个名为 SID 的值,类型为 REG_BINARY。这是如何创建的?有人可以帮我吗?

我需要这个的原因是我正在将域帐户迁移到本地用户并保留所有设置,但是因为这个密钥它不起作用。

这是我目前拥有的:

这是丢失的密钥,我不确定它来自哪里:

您可以将 SID 转换为其二进制表示形式并将其写入注册表,如下所示:

# Replace this with the actual target SID string
$SIDString = 'S-1-5-21-1518175382-1413263562-1473642471-31061' 

# Parse as SecurityIdentifier struct
$SID = [System.Security.Principal.SecurityIdentifier]::new($SIDString)

# Create a byte array to hold the binary representation
$binarySID = [byte[]]::new($SID.BinaryLength)

# Copy binary SID to byte array
$SID.GetBinaryForm($binarySID, 0)

# Write binary SID to registry
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList${SIDString}"
New-ItemProperty -Path $path -Name SID -PropertyType Binary -Value $binarySID