获取ip地址后3位并更新当前用户bat文件

Get the last 3 digits of the ip address and update current user bat file

我需要获取 运行 所在计算机的用户 IP 地址的最后 3 位数字。在我这样做之后,我想更新当前用户,用户名为 dra123(其中 123 代表 ip 地址)

我该怎么做? 这可以做到吗?

要获取 IPV4 的后三位数字:

for /F "tokens=4 delims=.:" %%G in (
    'ping -4 %COMPUTERNAME%^|find "Reply from"'
) do set "IP=000%%G"
set "last3digits=%IP:~-3%"

添加前导零,例如IP=192.168.1.2

给出 002

抱歉,我没有关于如何更改当前用户名的建议,但您可以使用下一个命令的输出来了解自己:

wmic USERACCOUNT where "name='%username%'" get * /format:Textvaluelist.xsl

wmic USERACCOUNT /?

wmic USERACCOUNT set /?

编辑 简而言之:不是微不足道的,不是一步到位的程序和很多后果。您将要更改 username(通常引用为 %username%),但在 字面上 中使用 username 是连贯的。例如(绝对不详尽列表):

for /F "tokens=*" %G in ('set^|find /I "%username%"') do @echo %G
for /F "tokens=*" %G in ('reg query "HKCU\Volatile Environment"^|find /I "%username%"') do @echo %G
for /F "tokens=*" %G in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"^|find /I "%username%"') do @echo %G

不确定Windows 进行所有更改以保持一致性(Windows XP 没有)