我正在登录和注销会话上编写Windows脚本宿主代码。当用户登录系统时,正在记录时间戳,当用户再次注销时,正在记录时间戳。我已经提到了下面的代码但是得到了一个错误作为预期的标识符,我发现很难解决它。
REM登录脚本:
for /f "Tokens=2 Delims=[]" %%i in ('ping -n 1 "%computername%"') do set IP=%%i
echo %username% logged ON %computername%, IP=%IP% @ %time% %date% >> F:\$\%username%.txt
REM注销脚本:
echo %username% logged OFF %computername% @ %time% %date% >> F:\$\%username%.txt
REM启动脚本:
for /f "Tokens=2 Delims=[]" %%i in ('ping -n 1 "%computername%"') do set IP=%%i
echo Started up, IP=%IP% @ %time% %date% >> F:\$\%computername%.txt
REM关闭脚本:
echo Shutdown @ %time% %date% >> F:\$\%computername%.txt