前阵子有朋友问我,怎么用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. Centos7 nginx提示错误 Access denied.

    SELinux will cause this error on CentOS/RHEL 7+ by default :( CentOS/RHEL 7+ 系统默认会因为SELinux出现这个报错 To ...

  2. Django学习手册 - 如何安装django 和 python ?

    整体步骤阐述:(windows环境下) 步骤一,下载python安装包 (和 jiango 压缩包) 步骤二,安装python 配置python的环境变量 步骤三,安装djang 方式一:pip in ...

  3. java在进程启动和关闭.exe程序

    /** * @desc 启动进程 * @author zp * @date 2018-3-29 */ public static void startProc(String processName) ...

  4. Linux下tar压缩解压缩命令详解

    tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...

  5. 【转】python模块分析之collections(六)

    [转]python模块分析之collections(六) collections是Python内建的一个集合模块,提供了许多有用的集合类. 系列文章 python模块分析之random(一) pyth ...

  6. matplotlib 直方图绘制详解

    n, bins, patches = plt.hist(datasets, bins, normed=False, facecolor=None, alpha=None) 函数说明 用于绘制多个数据集 ...

  7. dubbo源码分析12——服务暴露3_doExportUrls()方法分析

    本文紧接上文,doExportUrls()方法位于ServiceConfig类中,代码入口如下: private void doExportUrls() { List<URL> regis ...

  8. 8种Nosql数据库系统对比(转)

    导读:Kristóf Kovács 是一位软件架构师和咨询顾问,他最近发布了一片对比各种类型NoSQL数据库的文章. 虽然SQL数据库是非常有用的工具,但经历了15年的一支独秀之后垄断即将被打破.这只 ...

  9. Markdown中Latex 数学公式基本语法

    原文地址:http://blog.csdn.net/u014630987/article/details/70156489 Markdown中Latex 数学公式基本语法 公式排版 分为两种排版: - ...

  10. 【Tomcat】tomcat内存配置登记册

    20141202: 环境:windows2003 tomcat6.x jdk1.6 启动方式:windows服务方式启动 启动异常:java.lang.OutOfMemoryError: PermGe ...