我正在尝试通过当前使用C#在winxp上计划一次重新启动程序,我对其进行编程以在winxp中添加一个计划任务以在5分钟内重新启动,但是它并不总是有效,因为重新启动后机器时间可能会更改(有时间服务器在我的环境中)。因此这意味着计划的任务时间不正确,从而导致我的重启无法在预期的时间进行。
例如,当我添加计划的重启任务时,机器时间是上午11:05,而重启时间则计划是上午11:10。然后我将XP加入域并重新启动,时间与时间服务器和计算机同步,更改为1:01 pm。在这种情况下,计划的任务已在当天的上午11:10结束。当然是行不通的。
所以有人知道其他方法吗?
ps:此程序在将xp加入域之前使用,并且已计划重新启动,因为它是第二次重新启动,我需要它自动重新启动而无需用户交互
通过从C#启动新进程来使用内置的shutdown命令:
using System;
using System.Diagnostics;
namespace ShutdownApp
{
class ShutdownApp
{
static void Main(string[] args)
{
Process shutDown = new Process();
int shutdownTimeInSeconds = 600; // this will shutdown in 10 minutes, use DateTime and TimeSpan functions to calculate the exact time you need
shutDown.StartInfo.FileName = "shutdown.exe";
shutDown.StartInfo.Arguments = string.Format("-r -t {0}", shutdownTimeInSeconds);
shutDown.Start();
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
665 次 |
| 最近记录: |