批次只跳过定界符
我正在尝试使用命令行登录到注册表。但是我的用户名在一个空间之间有两个单词。例如:“猫狗”。好吧,如果我将空间用作定界符,它只会打印“猫”,如果我放置tokens = 3
,它也会打印在一起,因为这两个单词之间有一个空间。
我正在这样做以在许多计算机中使用,因此我无法确定每个计算机的精确用户名。我如何从令牌编号的第一个单词3
中的定界符,直到结束至关重要,它的空间有多少?
@echo off
for /f "tokens=3" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\1 /v LoggedOnUser') do (
set "user=%%a")
set "user=%user:.\=%"
echo %user%
pause
I'm trying to get my current username by registry using command line. But my username has two words between a space. Ex.: "Cat Dog". Well, if i use a space as delimiter, it only prints 'Cat', if i put tokens=3
it prints also the same because there's a space between these two words.
I'm doing it to use in many computers, so i can't determine the exactly username of each one. How can i delimiter from the first word of the token number 3
until the end not mattering how much spaces it has ?
@echo off
for /f "tokens=3" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\1 /v LoggedOnUser') do (
set "user=%%a")
set "user=%user:.\=%"
echo %user%
pause
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有什么原因您无法使用Whoami命令?例如:
Is there any reason you couldn't use the whoami command? For example:
Windows在环境中具有系统变量%用户名%
Windows has a system variable %username% in the environment