当前位置:首页 » 《资源分享》 » 正文

14 种编程语言书写关机脚本,真香_橡皮擦,一个逗趣的互联网高级网虫

14 人参与  2021年05月11日 13:03  分类 : 《资源分享》  评论

点击全文阅读


文章目录

    • 批处理版本
    • C 语言版本
    • C++ 语言版本
    • JAVA 语言版本
    • C# 语言版本
    • Python 语言版本
    • NodeJS 语言版本
    • PHP 语言版本
    • Perl 语言版本
    • Go 语言版本
    • VB 语言版本
    • SQL 语言版本
    • 树莓派 版本
    • 易语言 版本
    • 期待评论区

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

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

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

批处理版本

shutdown -s -t 60

C 语言版本

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

C++ 语言版本

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

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();
        }
    }
}

C# 语言版本

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

Python 语言版本

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

NodeJS 语言版本

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

PHP 语言版本

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

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);

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)
}

VB 语言版本

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

SQL 语言版本

exec xp_cmdshell 'shutdown -s -t 60'

树莓派 版本

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

易语言 版本

关闭系统 (#关机,)

期待评论区

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

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

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

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


点击全文阅读


本文链接:http://zhangshiyu.com/post/18808.html

版本  语言  评论  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1