Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file IF语句,如何使用当前时间显示错误_Batch File_Vbscript_Cmd - Fatal编程技术网

Batch file IF语句,如何使用当前时间显示错误

Batch file IF语句,如何使用当前时间显示错误,batch-file,vbscript,cmd,Batch File,Vbscript,Cmd,我正在学校系统的批处理文件中编写代码,代码显示学生何时更改了密码。 我有一个系统的问题,它表明,所有的学生用户名已经改变了密码,但一些用户显示当前的时间和日期。 我试图做一个if语句:if用户的日期和时间==当前日期和时间。显示回显消息 我尝试了很多代码,但似乎它们都不对 以下是其中一个代码: (for /f "delims=" %%i in ('net user %MyName% /domain ^| find /I "password last set"') do set MyResult=

我正在学校系统的批处理文件中编写代码,代码显示学生何时更改了密码。 我有一个系统的问题,它表明,所有的学生用户名已经改变了密码,但一些用户显示当前的时间和日期。 我试图做一个if语句:if用户的日期和时间==当前日期和时间。显示回显消息

我尝试了很多代码,但似乎它们都不对

以下是其中一个代码:

(for /f "delims=" %%i in ('net user %MyName% /domain ^| find /I "password last set"') do set MyResult=User 
%MyName%: %%i)

if "%DATE%-%TIME%" EQU "%MyResult%" echo "password not changed."
如果这段代码是在vbs中,那么它也将非常有用,这将是完美的


提前谢谢。:)

这里有一个VBScript供您使用。由于时间可能会随着
net user
返回的时间而略有变化,您有机会对其进行测试,因此此脚本将检查它是否在当前日期和时间的10秒内。您可以根据需要自由调整阈值

' Create the command string...
strCommand = "cmd /c net user " & strUser & " /domain | find ""Password last set"""

' Run the command and capture its output...
strOut = CreateObject("WScript.Shell").Exec(strCommand).StdOut.ReadAll

' Remove the label ("Password last set") leaving only the date and time...
strOut = Trim(Mid(strOut, Len("Password last set") + 1))

If IsDate(strOut) Then
    If Abs(DateDiff("s", strOut, Date)) < 10 Then

        ' Password set within last 10 seconds

    End If
End If    
'创建命令字符串。。。
strCommand=“cmd/c net user”&strUser&“/domain |查找“密码最后设置”
'运行命令并捕获其输出。。。
strOut=CreateObject(“WScript.Shell”).Exec(strCommand).StdOut.ReadAll
'删除标签(“密码最后设置”),只留下日期和时间。。。
strOut=修剪(中间(strOut,Len(“密码最后设置”)+1))
如果是IsDate(strOut),则
如果Abs(DateDiff(“s”,strOut,Date))<10,则
'在最近10秒内设置密码
如果结束
如果结束

在的
中获得%MyName%,但在
中检查%MyResult%(如果
)。打字错误?网络用户的输出是
18.03.2014 19:59:36
(日期和时间之间的空格)(至少在我的电脑上)。您检查
%DATE%-%TIME%
(日期和时间之间的破折号)