14 种编程语言书写关机脚本,真香

举报
梦想橡皮擦 发表于 2021/05/07 23:47:00 2021/05/07
【摘要】 文章目录 批处理版本C 语言版本C++ 语言版本JAVA 语言版本C# 语言版本Python 语言版本NodeJS 语言版本PHP 语言版本Perl 语言版本Go 语言版本VB 语言版本SQL 语言版本树莓派 版本易语言 版本期待评论区 五一到了,又到了程序员宅在家的时刻了。 有个家伙发来一个 BAT 的关机脚本,问我效果如何,然而我顺手给改成了 1...

五一到了,又到了程序员宅在家的时刻了。

有个家伙发来一个 BAT 的关机脚本,问我效果如何,然而我顺手给改成了 14 种编程语言版本的。

然后回复它一个:“就这?”

批处理版本

shutdown -s -t 60

  
 
  • 1

C 语言版本

#include <stdlib.h>
#include <stdio.h>
int main(void)
{ 
	system("shutdown -s -t 60"); 
	return 0;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

C++ 语言版本

#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
	system("shutdown -s -f -t 60");
	return 0;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

JAVA 语言版本

import java.io.IOException;
public class Shutdown60 { public static void main(String[] args) { try { Runtime.getRuntime().exec("shutdown -s -t 60"); } catch (IOException e) { e.printStackTrace(); } }
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

C# 语言版本

System.Diagnostics.Process p = new System.Diagnostics.Process(); 
p.Start("shutdown", "-s -t 60");

  
 
  • 1
  • 2

Python 语言版本

import os
os.system('shutdown /s /t 60 ')

  
 
  • 1
  • 2

NodeJS 语言版本

function FFO_ShutdownWindow() { var execSync = require('child_process').execSync; execSync('shutdown -s -t 60'); 
}

  
 
  • 1
  • 2
  • 3
  • 4

PHP 语言版本

<?php
$cmd = stripslashes('shutdown -r');
exec($cmd, $out);
?>

  
 
  • 1
  • 2
  • 3
  • 4

Perl 语言版本

use Win32;

$machine = Win32::NodeName();
$timeout = 60;
if($ARGV[0]){$timeout = $ARGV[0];}
$message = Win32::MsgBox("shut down after $timeout seconds.");
Win32::InitiateSystemShutdown($machine,$message,$timeout,true,true);

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Go 语言版本

package main
func main() {
	shutdown()
}
func shutdown() {
	getPrivileges()
	ExitWindowsEx(EWX_SHUTDOWN, 0)
}

func getPrivileges() {
	var hToken HANDLE
	var tkp TOKEN_PRIVILEGES

	OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken)
	LookupPrivilegeValueA(nil, StringToBytePtr(SE_SHUTDOWN_NAME), &tkp.Privileges[0].Luid)
	tkp.PrivilegeCount = 1
	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED
	AdjustTokenPrivileges(hToken, false, &tkp, 0, nil, nil)
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

VB 语言版本

private sub command_click() 
shell "shutdown -f -s -t 60"
end sub

  
 
  • 1
  • 2
  • 3

SQL 语言版本

exec xp_cmdshell 'shutdown -s -t 60'

  
 
  • 1

树莓派 版本

sudo shutdown -h now 
sudo halt 
sudo poweroff 
sudo init 0

  
 
  • 1
  • 2
  • 3
  • 4

易语言 版本

关闭系统 (#关机,)

  
 
  • 1

期待评论区

还有更多语言版本,实在是找不到了,希望大家在评论区给出代码吧,一经采用,博客立马更新。

例如:R 语言,Ruby 语言,Lua 语言,汇编语言

欢迎大家测试,测试之后,可以在评论区评论,XXX 语言版本已经实测,成功关机。

今天是持续写作的第 150 / 200 天。可以点赞、评论、收藏啦。

文章来源: blog.csdn.net,作者:梦想橡皮擦,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/hihell/article/details/116463138

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。