日期:2014-05-17  浏览次数:20924 次

c# 定时关闭程序 和 定时关机
关闭程序需要那种可以关闭所有运用程序的代码。。。。定时关机需要日期和时间那样的关机
可以做出来发我邮箱 924605975@qq.com

------解决方案--------------------
关闭程序:用API 强制注销用户
或者直接用Progress.Kill

定时关机可以用API 新建定时任务
或者直接用Progress.Start("shutdown", "-s at 2013-10-17 23:00:00"),但是它会显示倒计时窗口,要隐藏,可设置WindowStyle= WindowStyle.Hidden;
当然 你也可以用定时器,1分钟判断一下时间,到了就关机
------解决方案--------------------
我以前做过这样的小程序,很粗糙



[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
private static extern Boolean ExitWindowsEx(long uFlags, long dwReason);
[DllImport("kernel32.dll", ExactSpelling = true)]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool OpenProcessToken(IntPtr hwnd, int desiredAccess, ref IntPtr tokenHandle);
[DllImport("advapi32.dll", SetLastError = true)]
internal static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref long lpLuid);
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, bool DisableAllPrivileges, ref TokenPrivileges NewState, int BufferLength, IntPtr PreviousState, IntPtr ReturnLength);

------解决方案--------------------
定时关机程序:http://wenku.baidu.com/view/fa3cb135a32d7375a4178025.html
           http://blog.csdn.net/greystar/article/details/297363

加上定时器,
关闭进程
Process[] ps = Process.GetProcesses();
foreach (Process item in ps)
{
    if (item.ProcessName=="程序名")
    {
        item.Kill();
    }
}
------解决方案--------------------
写程序最好自己动手,这样你水平会提高 ,如果有碰到问题,这里大家给你方法和思路,