batch file - IF statement in cmd, how to use the current time to show an error -


i writing code in batch file school system, code shows when did student changed his/her password. had problem the system, shows student username have changed there password users show current time , date. trying make if statement saying: if date , time of user == date , time of current day. show echo message.

i have tried alot of codes work doesn't seem right.

here 1 of codes:

(for /f "delims=" %%i in ('net user %myname% /domain ^| find /i "password last set"') set myresult=user  %myname%: %%i)  if "%date%-%time%" equ "%myresult%" echo "password not changed." 

it useful if code in vbs perfect.

thank in advance. :)

here's vbscript you. since time may change time net user returns , have opportunity test it, script checks see if it's within 10 seconds of current date , time. feel free adjust threshold see fit.

' create command string... strcommand = "cmd /c net user " & struser & " /domain | find ""password last set"""  ' run command , capture output... strout = createobject("wscript.shell").exec(strcommand).stdout.readall  ' remove label ("password last set") leaving date , time... strout = trim(mid(strout, len("password last set") + 1))  if isdate(strout)     if abs(datediff("s", strout, date)) < 10          ' password set within last 10 seconds      end if end if     

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -