如何从命令行更改 regedit 注册表?

How to change regedit registry from command line?

我正在为我的域用户使用 "D:\users" profilePath。当我用新的 windows 图像更改我的 "systemdrive" 时,域用户会创建新的配置文件,例如 "D:\Users\old.DNS".

我想使用旧的配置文件路径,但找不到任何方法告诉 windows "use existing profile"。因此,我需要从 regedit 更改配置文件路径!

我试着写点东西,但我不知道如何修改注册表,只更改 "dnsname"。

因为每台机器的用户名都不同,不同公司的 DNS 名称也可能不同。

我正在使用

获取用户 sid
set sid=wmic useraccount where name='%username%' get sid

%sid%

然后我需要获取用户名并从中删除 .DNS,但我不知道该怎么做。 我可以写一些类似 "delete after " 的东西吗?"point" 批量?

我找到了自己,这个脚本需要管理员权限。

::get usersid first
for /F "tokens=2" %%i in ('whoami /user /fo table /nh') do set usersid=%%i

::get userpath
for /F "tokens=3" %%i in ('reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%usersid%" /v "ProfileImagePath"') do set oldpath=%%i

::delete after "."
for /f "tokens=1 delims=." %%a in ('echo %oldpath%') do set newpath=%%a

::update the reg with new path
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%usersid%" /v "ProfileImagePath" /t REG_EXPAND_SZ /d "%newpath%" /f

echo EVERYTHING OKAY MATE!
pause