Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
For loop 排除FOR循环中的字符_For Loop_Batch File_Cmd_Findstr_Regedit - Fatal编程技术网

For loop 排除FOR循环中的字符

For loop 排除FOR循环中的字符,for-loop,batch-file,cmd,findstr,regedit,For Loop,Batch File,Cmd,Findstr,Regedit,我想显示一个windows用户的ProfileImagePath值的相关信息,该用户的用户名中没有“\ux”字符: @echo off cls for /f %%I in ('dir /a:d-h /b C:\Users\ ^| %SystemRoot%\System32\findstr.exe /b /l /v "_"') do ( FOR /F "delims=" %%k IN ('reg query "HKLM\SOFTWA

我想显示一个windows用户的ProfileImagePath值的相关信息,该用户的用户名中没有“\ux”字符:

@echo off
cls
for /f %%I in ('dir /a:d-h /b C:\Users\ ^| %SystemRoot%\System32\findstr.exe /b /l /v "_"') do (
        FOR /F "delims=" %%k IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"^|findstr.exe /R "S-1-5-21-[0-9]*-[0-9]*-[0-9]*-[0-9]*$" 2^>nul') do (
        reg query "%%k" /v "ProfileImagePath"|findstr /i /e /c:"%%~I"
        )   
)
但是findstr命令还考虑了带有“ux”字符的用户,而在第一个FOR命令中,我排除了这个字符:

ProfileImagePath    REG_EXPAND_SZ    C:\Users\user1
ProfileImagePath    REG_EXPAND_SZ    C:\Users\_user1
怎么可能呢?如何在第二个FOR命令中考虑这一点?

findstr/i/e/c:“user1”
搜索以
user1
结尾的字符串。但是
\u user1
也以
user1
结尾:(


将其更改为
findstr/i/e/c:“\%%~i”
是解决您的问题的一种方法:)

对于您的问题,我有一些不明白的地方,如果您需要重点帮助,您可能需要正确解释。既然你已经开始使用一个命令,将那些已经被限制为
C:\Users
,为什么还要跳转来确定配置文件映像路径呢。当然
For/F“Delims=“%%G In('Dir“C:\Users”/B/A:D^|%SystemRoot%\System32\findStr.exe/B/V”quo;)Do@Echo C:\Users\%%G
将为您提供配置文件路径!