前阵子有朋友问我,怎么用C语言写一个小程序,控制电脑关机。这个我真的不懂,这几天闲着,就上网搜了搜,整理一下。

IDE: Code::Blocks 16.01

操作系统:Windows 7 x64

 #include <windows.h>

 int main()
{
system("shutdown -s -f -t 3600");
Sleep();
system("shutdown -a"); return ;
}

另外,需要添加链接库:libwsock32.a

右击工程,选“Build options...”

在“Project build options”对话框中,选“Linker settings” > “Add”,链接库“libwsock32.a”位于目录:CodeBlocks\MinGW\lib\

之后,一路yes、ok、ok


关于“Shutdown”的参考:https://technet.microsoft.com/en-us/library/bb491003.aspx

-s : Shuts down the local computer.

-a : Aborts shutdown. Ignores other parameters, except -l and ComputerName. You can only use -a during the time-out period.

-f : Forces running applications to close.

-t xx : Sets the timer for system shutdown in xx seconds. The default is 20 seconds.


嗯,时间不早了,准备睡觉,试试下面的代码,看看效果。

 #include <windows.h>

 int main()
{
system("shutdown -s -f -t 60"); return ;
}

C++ shut down a computer的更多相关文章

  1. BackTrack5-r3安装VMware Tools

    bt login:root //默认的BT系统账号password:toor //默认的BT系统密码,这里的密码是不显示的.root@bt:~#startx //进入图形模式 启动BT虚拟机系统-在V ...

  2. OS X: Keyboard shortcuts

    Using keyboard shortcuts To use a keyboard shortcut, press a modifier key at the same time as a char ...

  3. 多进程监控自动关机工具升级远程关闭多台server——C# works with PowerShell

    之前给单位做过一个多进程监控的自动关机工具,详见那篇blog. 这次领导又加了需求,说要等进程监控结束后,不止需要关闭主控端server,还需要关闭其他servers.于是就用到了我上篇文章所介绍的知 ...

  4. 用C#写一个多进程监控自动关机工具

    因为据说某server开着就很贵,所以我们跑完测试的job后就要赶紧关机才行,但是测试的job要跑很久,过程中又不需要干什么,所以就得有个守家的,有时候会走很晚.如果有一个自动化关机的工具就好了,当指 ...

  5. 用C#写一个实现进程监控的自动关机工具

    今天QA部门需要进行Performance测试,因为跑job的时间会很长,下班也跑不完.所以想要做一个job运行完毕自动关机的工具. 原理就是检查进程的名称,如果检查不到相应的进程,就说明job已经跑 ...

  6. Resetting the SMC & PRAM

    Resetting the SMC & PRAM on portables with a battery you should not remove on your own 1. Shut d ...

  7. 在Debian上用FVWM做自己的桌面

    用FVWM做自己的桌面 Table of Contents 1. 前言 2. 学习步骤 3. 准备 3.1. 软件包 3.2. 字体 3.3. 图片 3.4. 参考资料 4. 环境 5. 布局 6. ...

  8. A problem has been detected and windows has been shut down to prevent damage to your computer.他么啥意思?看这里!【蓝屏】

    A problem has been detected and windows has been shut down to prevent damage to your computer.  检测到问 ...

  9. 10 notorious computer virus

    The history of computer virus is the same as computer history. With more and more powerful computers ...

随机推荐

  1. 调试 - Visual Studio调试

    Visual Studio - 调试 异常处理机制 windows预定义了一系列的异常错误码,每种程序异常都有一个对应的错误码,windows系统将这些类似键值对关系的数据存储在异常处理表中(称为SE ...

  2. css3基础一

    1,css简介 CSS 用于控制网页的样式和布局.样式定义如何显示html元素,样式通常保存在外部的 .css 文件中.通过仅仅编辑一个简单的 CSS 文档,外部样式表使你有能力同时改变站点中所有页面 ...

  3. [转] Understanding Convolutional Neural Networks for NLP

    http://www.wildml.com/2015/11/understanding-convolutional-neural-networks-for-nlp/ 讲CNN以及其在NLP的应用,非常 ...

  4. eMMC基础技术11:flash memory

    [转]http://www.wowotech.net/basic_tech/367.html 0.前言 eMMC 是 Flash Memory 的一类,在详细介绍 eMMC 之前,先简单介绍一下 Fl ...

  5. wxpy: 用 Python 玩微信【转】

    转自:https://wxpy.readthedocs.io/zh/latest/index.html 微信机器人 / 可能是最优雅的微信个人号 API wxpy 在 itchat 的基础上,通过大量 ...

  6. genPanel.py

    #!/usr/bin/python # -*- coding: UTF-8 -*- import os import sys import re import shutil import glob ' ...

  7. java二分查找

    二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序排列,将表 ...

  8. zabbix3.2监控vcenter和exsi信息

    简介 为了解 ESXI虚拟主机的运行状况,通过zabbix进行监控,图形展示ESXI虚拟主机当前的状态,避免因为esxi服务器因为资源利用率过高导致 概述 从 Zabbix 2.2.0 开始支持对 V ...

  9. centos中释放缓存的方法

    释放缓存区内存的方法 a)清理pagecache(页面缓存) # > /proc/sys/vm/drop_caches 或者 # sysctl - b)清理dentries(目录缓存)和inod ...

  10. 使用python找出nginx访问日志中访问次数最多的10个ip排序生成网页

    使用python找出nginx访问日志中访问次数最多的10个ip排序生成网页 方法1:linux下使用awk命令 # cat access1.log | awk '{print $1" &q ...