非常感谢下面关于我的关注的任何帮助,我一直在互联网上搜索这个问题很长时间..
我想实现一个用户重启通知脚本,该脚本将检查用户的计算机是否未重启超过24小时;如果是,它将给出一个消息框,可以选择立即重启或稍后提醒他们一段时间然后它会再次弹出。如果用户选择了第三次提醒他们,脚本将强制重新启动倒计时。
我正在考虑通过GPO将其部署为每天运行的计划任务。如果用户的机器符合他们在24小时内重新启动的条件,那么它就什么都不做。
谢谢!
我看到了一些脚本并对其进行了一些修改..它可以工作但是如何在一天之后添加后续的小时和分钟?如果我添加另一个dateDiff来输出小时和分钟,我将整天转换为小时/分钟..
'Set the minimum number of days of uptime to begin issuing the warning.
WarnAfterDays = 0
Set objShell = wscript.createObject("wscript.shell")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2")
set colComp = objWMI.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem")
For Each item in colComp
dlastReboot = WMIDateStringToDate(item.LastBootUpTime)
dDiff = dateDiff("d",dLastReboot,Now)
if dDiff >= WarnAfterDays Then
do while 1>0
intRebootChoice = MsgBox("This computer has been running for " & dDiff & " days since " & dlastReboot & ". To keep the computer operating optimally a system restart
is recommended." & VBCRLF & VBCRLF & "PLEASE SAVE ALL YOUR WORK BEFORE RESTARTING." & VBCRLF & VBCRLF & "Would you like to restart your computer?" & VBCRLF & "[YES to
retstart now, NO to be reminded later]",308,"NOTICE - REBOOT REQUIRED")
select case intRebootChoice
case 6
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot(1)
Next
case 7
wscript.sleep(30000)
end select
loop
End if
Next
Function WMIDateStringToDate(dtmInstallDate)
WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
& " " & Mid (dtmInstallDate, 9, 2) & ":" & _
Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
13, 2))
End Function
答案 0 :(得分:0)
或许考虑使用PsShutdown。在每个工作站上安装它,您可以设置一些计划任务来触发它,或者您甚至可以使用管理UI远程触发服务器的关闭。您可以指定何时关闭,提供多少警告,向用户发送消息以及是否可以取消。这将为您提供所需的大部分功能,而无需编写任何代码。