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 ...
随机推荐
- Eclipse 各版本号
查看Eclipse版本号的方法:1.找到eclipse安装目录.2.进入readme文件夹,打开readme_eclipse.html.3.readme_eclipse.html呈现的第二行即数字版本 ...
- 微信小程序弹出可填写框两种方法
方法一: html页面: < view class = "container" class = "zn-uploadimg" > < butt ...
- nginx 端口映射多个应用
nginx端口映射多个应用,应用中的静态资源路径尽量是写相对路径 server { listen 8000; location / { proxy_pass http://10.1.166.216:9 ...
- PL/SQL 加字段 修改数据库之后 之后记得保存脚本
- webstorm设置VCS:版本控制顶部按钮
说明: 每次都在这坑一下,浪费时间,百度只指出在哪,并没有说怎么调出来 我用的版本是10,点击下面的选项按操作设置就可以了 红色箭头:从服务器获取最新代码: 绿色箭头:提交: 白色箭头:撤销
- selenium——获取元素的尺寸、文本信息、元素的属性、元素是否可见
[is_disabled 可以用来检查元素是否存在]
- NodeJS+Express+MySQL开发小记(2):服务器部署
http://borninsummer.com/2015/06/17/notes-on-developing-nodejs-webapp/ NodeJS+Express+MySQL开发小记(1)里讲过 ...
- springcloud-1: 用官方的pom.xml配置添加依赖失败
在eclipse中用STS生成了一个springcloud应用,pom.xml的核心配置如下: <parent> <groupId>org.springframework.bo ...
- object oriented programming : class application
class Thread_Sync; class Critical; class Info; class Info{Info(std::string str):m_info(str){} privat ...
- Linux查看所有用户和组信息
主要通过以下两个命令: cat /etc/passwd cat /etc/group 步骤一:cat /etc/passwd查看所有的用户信息,详情如下图: 步骤2:cat /etc/passwd|g ...