帮助创建计划任务

时间:2011-08-24 11:44:29

标签: vb.net time

我遇到了这个代码,它应该能够将我的PC时间与存储在TheTime中的时间进行比较;但是,我无法让它发挥作用。有人可以帮忙吗?

dim theTime as datetime

theTime = CDate(txtTime.Text)

if theTime.hour = now.hour and theTime.minute = now.minute then
'shut down code
System.Diagnostics.Process.Start("Shutdown.exe", "-s -t 0")
end if

2 个答案:

答案 0 :(得分:0)

尝试用now -

替换DateTime.now
dim theTime as datetime

theTime = CDate(txtTime.Text)

if theTime.hour = DateTime.now.hour and theTime.minute = DateTime.now.minute then
'shut down code
System.Diagnostics.Process.Start("Shutdown.exe", "-s -t 0")
end if

答案 1 :(得分:0)

Dim theTime as DateTime
theTime = CDate(txtTime.Text)
If theTime.hour = DateTime.now.hour and theTime.minute = DateTime.now.minute then
Shell("Shutdown /s") 'to shutdown
End if

您也可以尝试以下

Shell("Shutdwon /r") 'to restart
Shell("Shutdown /l") 'to logoff
Shell("Shutdown /a") 'to Abort