|
|
本帖最后由 ygqiang 于 2025-9-3 23:17 编辑
[已解决]pe或win系统,2种环境,批处理,如何获取x:\users目录下的个人用户名xxy?
有没有通用的命令,获取到这个xxy用户名?
(不同的电脑,pe系统或者win系统,这里显示的名称xxy不同)
(同一台电脑,pe系统或者win系统,这里显示的名称xxy是一样的)
(这个xxy用户名,是正常启动win系统,默认自动进入桌面后的用户名。)
(win系统下,%USERNAME%可以获取到xxy名称)
(pe系统下,%USERNAME%不能正常获取到xxy名称。)
pe系统,或win系统,切换到cd /d x:\users目录
运行下面命令,显示结果如下
dir /b显示:
xxy
Public
dir /b /a显示:
All Users
Default
Default User
desktop.ini
xxy
Public
豆包搜索下,问题解决。- @echo off & setlocal enabledelayedexpansion
- for %%a in (C D E F G H I J K L M N O P Q R S T U V W) do (
- if exist %%a:\Windows (
- set "pf=%%a"
- :: 设置Users目录路径
- set "users_dir=!pf!:\Users"
- :: 遍历目录,排除系统默认文件夹
- for /d %%a in ("!users_dir!\*") do (
- :: 排除公共文件夹和默认系统文件夹
- if /i not "%%~nxa"=="Public" (
- if /i not "%%~nxa"=="Default" (
- if /i not "%%~nxa"=="Default User" (
- echo "%%~nxa"
- 1pause & cls
- set "usna=%%~nxa"
- echo !usna!
- 1pause & cls
- ===================================================
- ===================================================
- cls
- call :next
- )
- )
- )
- )
- )
- )
- echo gggggggggg
- pause
- cls
- exit
- ===================================================
- ===================================================
- cls
- :next
- echo !pf!:\Users\!usna!
- pause
- cls
- GOTO :EOF
复制代码 |
|