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 ...
随机推荐
- Javascript入门(三)函数
Javascript函数 一.函数定义与执行 <script type="text/javascript"> //define function fun1(){ ale ...
- 围在栅栏中的爱WriteUp(附QWE密码加解密脚本)
题目的链接:http://www.shiyanbar.com/ctf/1917 1.首先题目给出的是摩尔斯电码: 在下面的网站上解密:https://www.cryptool.org/en/cto-c ...
- (转载)经典计算机视觉论文笔记——DeepFace\DeepID\DeepID2\DeepID3\FaceNet\VGGFace汇总
1. DeepFace:Closing the Gap to Human-Level Performance in Face Verification 最早将深度学习用于人脸验证的开创性工作.Face ...
- Mongoose简介
Mongoose 官网地址:http://mongoosejs.com/ ,Mongoose 为node.js提供了优雅的,针对mongodb的ODM(Object Document Mappin ...
- Git学习笔记04-管理修改
Git跟踪并管理的是修改,而非文件.新增文件,修改一行,删除一点,都算是修改. 在.git工作区新增一个文件,test.txt,输入test git ...然后git add add之后修改t ...
- 设计模式C++学习笔记之十五(Composite组合模式)
15.1.解释 概念:将对象组合成树形结构以表示“部分-整体”的层次结构.Composite使得用户对单个对象和组合的使用具有一致性. main(),客户 CCorpNode,抽象基类,实现基本信 ...
- latex中的希腊字母
原文地址:http://blog.csdn.net/xxzhangx/article/details/52778539 希腊字母,我们从小学开始认识它,但对它的读音我依旧靠蒙(说蒙真的感觉好羞愧啊). ...
- zTree:一个依靠 jQuery 实现的多功能 “树插件”
官方网站: http://www.treejs.cn/v3/main.php#_zTreeInfo 使用方式: 步骤1.文件准备 将需要使用的 zTree v3.x 相关的 js.css.img 文件 ...
- 在VS解决方案资源管理器中自动定位当前编辑中的文件
依次点击 [工具]- [选项] - [项目和解决方案]-[常规]- 勾选[在解决方案资源管理器中跟踪活动项]
- spring3.1 profile 配置不同的环境
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...