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 ...
随机推荐
- A Simple Problem with Integers POJ - 3468 (分块)
题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的 ...
- mongodb系列~配置文件的优化与处理
一 简介:讲讲如何优化mongo配置文件二 常规参数 port= //端口 fork=true//守护进程方式启动mongo logpath=shard.log //mongo ...
- 目标检测:YOLO(v1 to v3)——学习笔记
前段时间看了YOLO的论文,打算用YOLO模型做一个迁移学习,看看能不能用于项目中去.但在实践过程中感觉到对于YOLO的一些细节和技巧还是没有很好的理解,现学习其他人的博客总结(所有参考连接都附于最后 ...
- vue购物车实战项02
1.数据循环.绑定 v- 绑定的属性 都是变量 ( 小程序这块需要花括号 不同点) 2.列表点击 当绑定变量为一个对象的时候{} 属性根据里面的属性值 bool 值 是否返回 当前的属性 转化成cl ...
- 通用redis命令
Redis五种数据类型,String,hash,list,set,有序set keys pattern:获取所有与pattern匹配的key,返回所有与该key匹配的keys. 通配符: *表示任意0 ...
- 网络爬虫re模块的findall()函数
findall()函数匹配所有符合规律的内容,并以列表的形式返回结果. a = '"<div>指数' \ '</div>"' word = re.finda ...
- TextArea 保存时换行符处理
后台数据保存时就要处理“\r\n",替换成”<br />",前台(html)页面显示时再做下处理. 自己是mvc页面,用到了两个方法:Html.Raw(),以及Http ...
- unity开发笔记
debug代码 Debug.Log("普通信息"); Debug.LogWarning("警告信息"); Debug ...
- 第三章 Models详解
摘自:http://www.cnblogs.com/xdotnet/archive/2012/03/07/aspnet_mvc40_validate.html Model的概念 万丈高楼平地起,先理解 ...
- Nikitosh 和异或 —— 一道 trie 树的题用可持久化 trie 水 然后翻车了...
题意简介 题目就是叫你找两个不重合的非空区间,使得这两个区间里的数异或后相加的和最大 (看到异或,没错就决定是你了可持久化trie!) 思路 水一波字典树,莫名觉得这题可持久化能过,于是水了一发挂了, ...