C++ shut down a computer
前阵子有朋友问我,怎么用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的更多相关文章
- BackTrack5-r3安装VMware Tools
bt login:root //默认的BT系统账号password:toor //默认的BT系统密码,这里的密码是不显示的.root@bt:~#startx //进入图形模式 启动BT虚拟机系统-在V ...
- OS X: Keyboard shortcuts
Using keyboard shortcuts To use a keyboard shortcut, press a modifier key at the same time as a char ...
- 多进程监控自动关机工具升级远程关闭多台server——C# works with PowerShell
之前给单位做过一个多进程监控的自动关机工具,详见那篇blog. 这次领导又加了需求,说要等进程监控结束后,不止需要关闭主控端server,还需要关闭其他servers.于是就用到了我上篇文章所介绍的知 ...
- 用C#写一个多进程监控自动关机工具
因为据说某server开着就很贵,所以我们跑完测试的job后就要赶紧关机才行,但是测试的job要跑很久,过程中又不需要干什么,所以就得有个守家的,有时候会走很晚.如果有一个自动化关机的工具就好了,当指 ...
- 用C#写一个实现进程监控的自动关机工具
今天QA部门需要进行Performance测试,因为跑job的时间会很长,下班也跑不完.所以想要做一个job运行完毕自动关机的工具. 原理就是检查进程的名称,如果检查不到相应的进程,就说明job已经跑 ...
- Resetting the SMC & PRAM
Resetting the SMC & PRAM on portables with a battery you should not remove on your own 1. Shut d ...
- 在Debian上用FVWM做自己的桌面
用FVWM做自己的桌面 Table of Contents 1. 前言 2. 学习步骤 3. 准备 3.1. 软件包 3.2. 字体 3.3. 图片 3.4. 参考资料 4. 环境 5. 布局 6. ...
- 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. 检测到问 ...
- 10 notorious computer virus
The history of computer virus is the same as computer history. With more and more powerful computers ...
随机推荐
- 20165234 《Java程序设计》第七周学习总结
第七周学习总结 教材内容学习 第十一章 JDBC与MySQL数据库 连接数据库: 1. 下载JDBC-MySQL数据库驱动 2. 加载JDBC-MySQL数据库驱动 3. 连接数据库 条件与排序查询: ...
- 使用CloneDB克隆数据库
本节包含以下主题: 关于使用CloneDB克隆数据库 使用CloneDB克隆数据库 使用CloneDB克隆数据库后 关于使用CloneDB克隆数据库 出于测试目的或其他目的克隆生产数据库通常是必要的. ...
- 数字图像处理的Matlab实现(3)—灰度变换与空间滤波
第3章 灰度变换与空间滤波(1) 3.1 简介 空间域指的是图像平面本身,这类方法是以对图像像素直接处理为基础的.本章主要讨论两种空间域处理方法:亮度(灰度)变换与空间滤波.后一种方法有时涉及到邻域处 ...
- Linux系统特点
自由软件 真正的多用户.多任务操作系统 极强的平台可伸缩性 强大的管理功能 强大的网络功能
- android Gui系统之SurfaceFlinger(1)---SurfaceFlinger概论【转】
转自:https://www.cnblogs.com/deman/p/5584198.html 阅读目录 1.OpenGL & OpenGL ES 2.Android的硬件接口HAL 3.An ...
- 最长增长子序列(LIS)
给定一个无序的整数数组,找到其中最长上升子序列的长度. 示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4. 说 ...
- python3+selenium框架设计08-进一步实现POM
之前都是只有一个页面,一个用例.这次两个页面.两个测试用例.其实界面自动化测试最大的难点在于driver的传递,需要保持唯一性.另外就是断言的难点. 修改之前的BaiduPage,新增部分代码 fro ...
- linux 新机器的配置(git + nodejs+ mongodb)
安装nodejs: wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz tar xvf node-v6.9.5-linux ...
- Ubuntu升级GCC到gcc4.8
http://www.qtcn.org/bbs/apps.php?q=diary&a=detail&did=1456&uid=139371Ubuntu最新gcc版本在ppa:u ...
- importlib模块
importlib模块 import importlib根据这个字符串来导入这个模块的 a=importlib.import_module('xx.oo')print(a.Person())里面可以传 ...