前阵子有朋友问我,怎么用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的更多相关文章

  1. BackTrack5-r3安装VMware Tools

    bt login:root //默认的BT系统账号password:toor //默认的BT系统密码,这里的密码是不显示的.root@bt:~#startx //进入图形模式 启动BT虚拟机系统-在V ...

  2. OS X: Keyboard shortcuts

    Using keyboard shortcuts To use a keyboard shortcut, press a modifier key at the same time as a char ...

  3. 多进程监控自动关机工具升级远程关闭多台server——C# works with PowerShell

    之前给单位做过一个多进程监控的自动关机工具,详见那篇blog. 这次领导又加了需求,说要等进程监控结束后,不止需要关闭主控端server,还需要关闭其他servers.于是就用到了我上篇文章所介绍的知 ...

  4. 用C#写一个多进程监控自动关机工具

    因为据说某server开着就很贵,所以我们跑完测试的job后就要赶紧关机才行,但是测试的job要跑很久,过程中又不需要干什么,所以就得有个守家的,有时候会走很晚.如果有一个自动化关机的工具就好了,当指 ...

  5. 用C#写一个实现进程监控的自动关机工具

    今天QA部门需要进行Performance测试,因为跑job的时间会很长,下班也跑不完.所以想要做一个job运行完毕自动关机的工具. 原理就是检查进程的名称,如果检查不到相应的进程,就说明job已经跑 ...

  6. Resetting the SMC & PRAM

    Resetting the SMC & PRAM on portables with a battery you should not remove on your own 1. Shut d ...

  7. 在Debian上用FVWM做自己的桌面

    用FVWM做自己的桌面 Table of Contents 1. 前言 2. 学习步骤 3. 准备 3.1. 软件包 3.2. 字体 3.3. 图片 3.4. 参考资料 4. 环境 5. 布局 6. ...

  8. 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.  检测到问 ...

  9. 10 notorious computer virus

    The history of computer virus is the same as computer history. With more and more powerful computers ...

随机推荐

  1. Css - 三大特性

    css - 三大特性 1.层叠性 如果通过两个相同选择器设置了同一个元素的某个相同的css属性,按照css相同属性的出现顺序,后面的样式会覆盖前面的样式 2.继承性 祖先元素的关于文本的样式会遗传给后 ...

  2. MySql cmd下的学习笔记 —— 引擎和事务(engine,transaction)

    engine 引擎就是MySQL存储数据的不同方式 myisam 插入速度快 支持全文索引 innoDB 插入速度慢 支持事务安全 假设两人同时购买火车票,两人同时看到只有一张火车票,几乎同时下单 或 ...

  3. Spring boot中普通工具类不能使用@Value注入yml文件中的自定义参数的问题

    在写一个工具类的时候,因为要用到yml中的自定义参数,使用@Value发现值不能正常注入,都显示为null: yml文件中的自定义格式 调用工具类的时候不能new的方式 要使用@Autowired的方 ...

  4. Eclipse使用solrJ 7.7.0连接solr步骤

    先写一个测试类: package com.taotao.rest.solrj; import org.apache.solr.client.solrj.SolrClient; import org.a ...

  5. 序列化 java.io.Serializable

    1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态,并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存Object States,但是Java给你提供一种应该比 ...

  6. python类的内建方法

    研究email源码学到的 class test(): """Class for generating text/* type MIME documents."& ...

  7. 微信小程序弹出层点击穿透问题

    问题描述:使用小程序的modal组件实现遮罩层效果时,会出现滚动穿透的问题,即遮罩层后面的页面依旧可以滚动. 解决方案: 给底层页面动态添加 position:fixed; 代码: wxml: < ...

  8. Qt5全局热键第三方库qxtglobalshortcut5使用

    1.下载第三方库https://github.com/ddqd/qxtglobalshortcut5. 2.把qxtglobalshortcut5文件放在项目目录下,在项目.pro加入一句,inclu ...

  9. python操作三大主流数据库(6)python操作mysql⑥新闻管理后台功能的完善(增、ajax异步删除新闻、改、查)

    python操作mysql⑥新闻管理后台功能的完善(增.删.改.查)安装表单验证D:\python\python_mysql_redis_mongodb\version02>pip instal ...

  10. Solidworks设计电路外形导入AltiumDesigner

    将实际设计好的三维电路图的底板(单个零件模式下)轮廓另存为dwf或者dwg 这时候会出现一个选项框,需要进行一些设置 单位选择mm,这个按照自己的需求选择单位 单位映射选择为1mm,也就是1:1的比例 ...