zoukankan      html  css  js  c++  java
  • 关机

    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using UnityEngine;
     
    public class shutdown : MonoBehaviour {
     
        public string ShutDownDate = "19:00";
     
        bool Switch;
     
        void Awake()
        {
            OpenData();
        }
     
        void Update ()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                WindowsShutDown();
            }
     
            if (DateTime.Now.ToString("HH/mm").Contains(ShutDownDate))
            {
                if (!Switch)
                {
                    Switch = true;
                    WindowsShutDown();
                }
            }
     
        }
     
        void OpenData()
        {
            string path = Application.streamingAssetsPath + "/data.txt";
            if (File.Exists(path))
            {
                try
                {
                    StreamReader streamReader = File.OpenText(path);
                    ShutDownDate = streamReader.ReadToEnd();
                    streamReader.Dispose();
                }
                catch (Exception e)
                {
                    Debug.LogWarning(e.Message);
                }
            }
        }
     
        void WindowsShutDown()
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/c " + "shutdown -s -t 10";
            p.Start();
            WindowsMessage.AutoShutDown();
            Application.Quit();
        }
    }
     
     
     
    /// <summary>
    /// 调用外部库
    /// </summary>
    public class WindowsMessage
    {
        [DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
        public static extern int MessageBox(IntPtr handle, String message, String title, int type);//具体方法
        public static void AutoShutDown()
        {
            WindowsMessage.MessageBox(IntPtr.Zero, "倒计时10秒之后关机", "关机,下班!", 0);
        }
    }
  • 相关阅读:
    动态规划----查找一个数组中存在的数学数列
    java数据结构和算法------第八章
    java数据结构和算法-----第七章
    04002_HTML表单
    雷林鹏分享:PHP 高级过滤器
    雷林鹏分享:Lua 函数
    雷林鹏分享:Lua 流程控制
    雷林鹏分享:Lua 循环
    雷林鹏分享:Lua 变量
    雷林鹏分享:Lua 数据类型
  • 原文地址:https://www.cnblogs.com/AllNighter/p/14468814.html
Copyright © 2011-2022 走看看