五一到了,又到了程序员宅在家的时刻了。
有个家伙发来一个 BAT 的关机脚本,问我效果如何,然而我顺手给改成了 14 种编程语言版本的。
然后回复它一个:“就这?”
shutdown -s -t 60
#include
#include
int main(void)
{
system("shutdown -s -t 60");
return 0;
}
#include
#include
using namespace std;
int main(){
system("shutdown -s -f -t 60");
return 0;
}
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();
}
}
}
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.Start("shutdown", "-s -t 60");
import os
os.system('shutdown /s /t 60 ')
function FFO_ShutdownWindow() {
var execSync = require('child_process').execSync;
execSync('shutdown -s -t 60');
}
$cmd = stripslashes('shutdown -r');
exec($cmd, $out);
?>
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);
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)
}
private sub command_click()
shell "shutdown -f -s -t 60"
end sub
exec xp_cmdshell 'shutdown -s -t 60'
sudo shutdown -h now
sudo halt
sudo poweroff
sudo init 0
关闭系统 (#关机, 真)
还有更多语言版本,实在是找不到了,希望大家在评论区给出代码吧,一经采用,博客立马更新。
例如:R 语言,Ruby 语言,Lua 语言,汇编语言
欢迎大家测试,测试之后,可以在评论区评论,XXX 语言版本已经实测,成功关机。
今天是持续写作的第 150 / 200 天。可以点赞、评论、收藏啦。