当Windows 7中的用户登录时,配置文件已损坏,他们将获得一个空白配置文件。我可以通过进入注册表并删除临时配置文件,设置引用计数和状态值来轻松修复。我被困在我的批处理中,因为我从注册表中提取的是添加2个空格到注册表项名称,一旦我在批处理中调用它。如果我回显%SID%,它返回正确的值,没有可见的空格。注册表确实有%SID%和%SID%.巴克
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /F "skip=1 delims=" %%j in ('wmic useraccount where name^="%username%" get SID') do (
set SID=%%j
goto :DONE
)
:DONE
echo SID=%SID%
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%SID%.bak"
pause
批次结果:
SID=S-1-5-21-1559011707-81249799-2450556423-1000
Permanently delete the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Window
s NT\CurrentVersion\ProfileList\S-1-5-21-1559011707-81249799-2450556423-1000 .b
ak (Yes/No)? y
ERROR: The system was unable to find the specified registry key or value.
Press any key to continue . . .
正如您所看到的,输出在SID和文件扩展名后放了2个空格
有什么想法吗?
3条答案
按热度按时间55ooxyrt1#
查询结果以UCS-2 LE编码,而不是ANSI。在捕获
wmic
的输出时,我发现有时向查询添加一个一次性列并使用/format:csv
来保留格式会很有帮助。a0zr77ik2#
MarcB是对的,var是不正确的,因为结尾有空格。
您可以在
echo
中检查带引号的空白,并使用delims= "
解决它6ss1mwsb3#
只要加上这个:
这将删除所有空间!