QQDownload关机后关闭系统代码

本文介绍了一款针对QQDownload下载完成后自动关机的小工具。该工具通过检测QQDownload进程状态,在下载完成后自动关闭计算机系统,有效避免了系统空闲造成的资源浪费。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     QQDownload 其自身带有“完成后关机”的功能,然而 完成下载后,只是关掉自身的进程,实现关闭程序,并未关机。完成后系统却还开着,浪费电。

如何实现其自动关机,小虾自己做了一个程序,解决了这个问题。

整体思路是这样:

1,启动关机 程序;

2,检测QQDownload是否运行;

3,完成后关机。

下面附出实现代码,可能比较冗余,请大家见谅。

1GetSysProcess.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace ShotDownSys
{
    class GetSysProcess
    {
        private List<string> GetSysProc()
        {
            Process[] Curprocess = Process.GetProcesses();
            List<string> pList = new List<string>();//定义一个List
            foreach (Process p in Curprocess)
            {
                pList.Add(p.ProcessName.ToString());
            }
            return pList;
        }
        //获取字符Array
        public List<string> SysProcInfo()
        {
            return GetSysProc();
        }
        public string[] SysProcInfo_String()
        {
            Process[] Curprocess = Process.GetProcesses();
            string[] pList = new string[Curprocess.Length];
            for (int i = 0; i < Curprocess.Length; i++)
            {
                pList[i] = Curprocess[i].ProcessName;
            }
            return pList;
        }
    }
}

 

Form1.cs代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Timers;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace ShotDownSys
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DateTime dt = Convert.ToDateTime("00:00:59");
        private GetSysProcess gsp;
        //private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private List<string> pList;
        private string[] pstr;
        private void button1_Click(object sender, EventArgs e)
        {
            comboBox1.Enabled = false;
            timer1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            comboBox1.Enabled = true;
            FillControl();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //gsp = new GetSysProcess();
            //pstr = gsp.SysProcInfo_String();
            //contextMenu1.MenuItems.Add(this.MenuItem1.);
            this.contextMenu1.MenuItems.Add(this.menuItem2.CloneMenu());
            this.contextMenu1.MenuItems.Add(this.menuItem3.CloneMenu());
            this.notifyIcon1.ContextMenu = this.contextMenu1;
            FillControl();

        }
        private void FillControl()
        {
            gsp = new GetSysProcess();
            pstr = gsp.SysProcInfo_String();
            comboBox1.Items.Clear();
            comboBox1.Items.AddRange(pstr);
           
            listBox1.Items.Clear();
            listBox1.Items.AddRange(pstr);
        }
        private void start()
        {
            if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请选择进程");
                return;
            }
            string pSelect = comboBox1.Text;
            gsp = new GetSysProcess();
            pList = gsp.SysProcInfo();
            int i = pList.FindIndex(delegate(string str) { return str == pSelect; });
            //MessageBox.Show(i.ToString());
            if (i == -1)
            {
                timer1.Enabled = false;
                timer2.Enabled = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            FillControl();
           // MessageBox.Show("OK");
            start();
        }
        private void ShutDownSys()
        {

            if (dt != Convert.ToDateTime("00:00:00"))
            {
                this.Text = dt.Second.ToString() + "Second Left!";
                //MessageBox.Show(dt.Second.ToString()+"Second Left!");
                dt = dt.AddSeconds(-1);
            }
            else
            {
                DoExitWin(EWX_SHUTDOWN);
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            ShutDownSys();
        }


        [StructLayout(LayoutKind.Sequential, Pack = 1)]

        internal struct TokPriv1Luid
        {
            public int Count;

            public long Luid;

            public int Attr;

        }

        [DllImport("kernel32.dll", ExactSpelling = true)]

        internal static extern IntPtr GetCurrentProcess();

        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]

        internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

        [DllImport("advapi32.dll", SetLastError = true)]

        internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]

        internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,

         ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]

        internal static extern bool ExitWindowsEx(int flg, int rea);

        internal const int SE_PRIVILEGE_ENABLED = 0x00000002;

        internal const int TOKEN_QUERY = 0x00000008;

        internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;

        internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";

        internal const int EWX_LOGOFF = 0x00000000;

        internal const int EWX_SHUTDOWN = 0x00000001;

        internal const int EWX_REBOOT = 0x00000002;

        internal const int EWX_FORCE = 0x00000004;

        internal const int EWX_POWEROFF = 0x00000008;
       internal const int EWX_FORCEIFHUNG = 0x00000010;
        private void DoExitWin(int flg)
        {

            bool ok;

            TokPriv1Luid tp;

            IntPtr hproc = GetCurrentProcess();

            IntPtr htok = IntPtr.Zero;

            ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
            tp.Count = 1;
            tp.Luid = 0;
            tp.Attr = SE_PRIVILEGE_ENABLED;
            ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
            ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
            ok = ExitWindowsEx(flg, 0);
        }

        private void Form1_MinimumSizeChanged(object sender, EventArgs e)
        {
            MessageBox.Show("OK");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            this.Hide();
            this.notifyIcon1.Visible = true;
        }
        //
        private void MenuItem1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            this.Hide();
            this.notifyIcon1.Visible = true;
        }
        //
        private void MenuItem2_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.Show();
            this.notifyIcon1.Visible = false;
        }

        private void menuItem2_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            this.Hide();
            this.notifyIcon1.Visible = true;
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.Show();
            this.notifyIcon1.Visible = false;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

    }
}

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值