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 ...
随机推荐
- HashSet、TreeSet和LinkedHashSet分别基于HashMap、TreeMap和LinkedHashMap
1.如果你需要一个访问快速的Set,你应该使用HashSet: 当你需要一个排序的Set,你应该使用TreeSet: 当你需要记录下插入时的顺序时,你应该使用LinedHashSet. 2.因为Tre ...
- EasyGui的一个小例子
EasyGui的安装:首先下载easyGui安装包,地址链接:https://pan.baidu.com/s/1D8f_eXWn7l8xhcTuEsqZmA 密码:e5z5 安装步骤: 1.进入eas ...
- Log4j日志根据配置输出到多个自定义文件
最近工作中遇到所有日志需要记录到一个文件,而错误的sql执行记录到另一个文件中,查询了一些资料搞定,记录下来.顺便吐槽下公司限制印象笔记的使用. ##log4j.rootLogger=INFO, CO ...
- webrtc学习笔记
获取笔记本摄像头视频流 <html> <meta http-equiv="Content-Type" content="text/html; chars ...
- GeoDesc: Learning Local Descriptors by Integrating Geometry Constraints
这篇论文提出了一种新的局部描述子学习方法,有一些点值得学习,记录下来以供参考.文章中涉及了一些3D reconstruction.structure from 的知识,不是很了解,所以理解可能有偏颇. ...
- 当linux中的所有指令突然不能使用的时候
接到同事电话,线上linux系统所有命令执行不了(由于其误操作执行一些命令) 此时可以按以下步骤解决问题: 1.首先导入临时变量(重启虚拟机之后失效),使得所有命令行暂时可以用 直接在命令行执行以下命 ...
- Linux中目录proc/net/dev详解【转】
转自:https://blog.csdn.net/yzy1103203312/article/details/77848192 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- 007grafana监控时间戳转换
一. https://d.jyall.me/dashboard-solo/db/soloview?panelId=1&var-metrics=stats.gauges.zookeeper.mo ...
- 51nod--1256 乘法逆元 (扩展欧几里得)
题目: 1256 乘法逆元 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < ...
- java后台发送请求并获取返回值(续)
在java后端发送请求给另一个平台,从而给前端实现 "透传"的过程中,出现:数据请求到了并传到了前端,但是控制台打印时中文显示Unicode码而前端界面中中文显示不出来!!!开始怀 ...