列出C:\ users中所有用户配置文件的命令行/脚本 [英] Command line/Script to list all users profiles in C:\users
问题描述
我正在尝试创建一个非常简单的脚本,该脚本将在 c:\ users
中显示所有用户个人资料,例如:
I am trying to create a very simple script that will display all the User profiles in c:\users
like:
%User1%
%User2%
我尝试将WMIC与循环一起使用,但它挂起了....
I have tried using WMIC with a loop and it just hangs....
for /f "tokens=* skip=1" %%a in ('wmic UserAccount get Name') do (
if not "%%a"=="" (
)
)
任何帮助将不胜感激.
推荐答案
以下示例与我在我的评论,应该只列出普通"用户名,他们的本地配置文件位于C:\Users
.
The following example, unlike that which I provided in my comment, should list only 'normal' UserNames, who have their local profile location within C:\Users
.
正常"是指它应忽略默认",来宾"和管理员"之类的帐户.
By 'normal' what I mean is that it should ignore accounts like 'Default' 'Guest' and 'Admin' for example.
请注意,正如我前面提到的注释中已经提到的那样,用户名对于当前系统中的用户名将是正确的,但不一定是其配置文件目录父名称中使用的名称.
@Echo Off & SetLocal EnableExtensions
For /F Tokens^=2^ Delims^=^" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe Path
Win32_UserProfile Where "Special!='TRUE' And LocalPath Like 'C:\\Users\\%%'"
Assoc:List 2^>NUL') Do For /F Tokens^=4^ Delims^=^" %%H In ('
%SystemRoot%\System32\wbem\WMIC.exe UserAccount Where "SID='%%G'" Assoc:List
/ResultRole:SID 2^>NUL') Do Echo %%H
Pause
如果要通过CLI(而不是通过GUI)运行此批处理文件,则可以删除脚本底部的 Pause
命令.
您也可以直接在命令提示符中运行它:
You could also run it directly in the Command Prompt:
For /F Tokens^=2^ Delims^=^" %G In ('%SystemRoot%\System32\wbem\WMIC.exe Path Win32_UserProfile Where "Special!='TRUE' And LocalPath Like 'C:\\Users\\%'" Assoc:List 2^>NUL') Do @For /F Tokens^=4^ Delims^=^" %H In ('%SystemRoot%\System32\wbem\WMIC.exe UserAccount Where "SID='%G'" Assoc:List /ResultRole:SID 2^>NUL') Do @Echo %H
这篇关于列出C:\ users中所有用户配置文件的命令行/脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!