hta 定时关机重启实现代码

随心笔谈1年前 (2023)发布 admin
106 0

一个用于定时重启或关闭计算机的小工具,适用于Windows 2K/XP/2003

id=”WTimer”

maximizebutton=”No”

minimizebutton=”Yes”

singleinstance=”Yes”

contextmenu=”Yes”

sysmenu=”Yes”

version=”1.0″

innerborder=”No”

caption=”Yes”

showintaskbar=”Yes”

border=”Normal”

borderstyle=”Normal”

applicationname=”Windows Timer”

icon=”TimerIco.ico”

/>

* { font-family:Courier New,Arial,Sans-serif;font-size:9pt; }

body { overflow-y:hidden; }

div a:link,div a:visited { text-decoration:none;color:#000 }

div a:hover { text-decoration:underline;color:#f00 }

#footerinfo { width:100%;display:table;margin-top:5px; }

#left { float:left;width:70%; }

#right { float:right;width:29%;text-align:right;margin-right:1px; }

–>

$bl_Sleep=false;

function getObject($obj) {

return(document.getElementById($obj));

}

String.prototype.parseInt=function() {

return(parseInt(this));

}

function getRadioVal($name) {

$oEms=document.getElementsByName($name);

for ($i=0;$i<$oEms.length;$i++) {

if ($oEms[$i].checked) { return($oEms[$i].value); }

}

}

function isDeclared($varName) {

return(typeof($varName)!=”undefined”);

}

function chStatus($name,$status) {

$ooEms=document.getElementsByName($name);

for ($a=0;$a<$ooEms.length;$a++) {

$ooEms[$a].disabled=$status;

}

}

function window.onload() {

$sWidth=window.screen.width;

$sHeight=window.screen.height;

$aWidth=400;

$aHeight=185;

window.resizeTo($aWidth,$aHeight);

window.moveTo(($sWidth-$aWidth)/2,($sHeight-$aHeight)/2);

document.bgColor=”#d4d0c8″;

getObject(“StopButton”).disabled=true;

getObject(“left”).innerHTML=”提示:请选择您想要使用的功能!”;

}

function Timer_Quit() {

window.close();

}

function Timer_Kernel() {

if ($bl_Sleep) {

if (isDeclared($time) && isDeclared($mod_time) && isDeclared($operation)) {

if ($time>0) {

$Oper_str=””;

$Hint_str=””;

$Titl_str=””;

if ($operation==”rWin”) {

$Oper_str=”提示:系统计时重启功能已启用,请注意保存!“;

}

else {

$Oper_str=”提示:系统计时关闭功能已启用,请注意保存!“;

}

if ($mod_time==”mod_minute”) {

$tMinute=($time/60).toString().parseInt();

$tSecond=$time%60;

if ($tMinute!=0) {

if ($tSecond<10) {

$tSecond=”0″+$tSecond;

}

$Titl_str=”剩余时间:”+$tMinute+”分”+$tSecond+”秒”;

}

else {

$Titl_str=”剩余时间:”+$tSecond+”秒”;

}

}

else {

$Titl_str=”剩余时间:”+$time+”秒”;

}

getObject(“left”).innerHTML=$Oper_str;

document.title=$Titl_str;

$time=$time-1;

$o=setTimeout(“Timer_Kernel()”,1000);

}

else {

$Flag=””;

if ($operation==”rWin”) {

$Flag=6; //6为重启操作系统

}

else {

$Flag=1; //1为关闭操作系统

}

OperateWin32($Flag);

getObject(“left”).innerHTML=”提示:正在执行预定操作!“;

document.title=”正在执行预定操作”;

}

}

}

}

function Timer_Stop() {

$bl_Sleep=false;

if (isDeclared($o)) { clearTimeout($o); }

getObject(“time”).disabled=false;

getObject(“mod_time”).disabled=false;

chStatus(“operation”,false);

getObject(“StartButton”).disabled=false;

getObject(“StopButton”).disabled=true;

getObject(“left”).innerHTML=”提示:请选择您想要使用的功能!”;

document.title=”♀Windows系统计时器♀”;

}

function Timer_Start() {

$bl_Sleep=true;

$nowTime=””;

$time=getObject(“time”).value;

$mod_time=getObject(“mod_time”).value;

$operation=getRadioVal(“operation”);

if (isNaN($time) || $time==””) {

alert(“请正确设定一个时间值! “);

getObject(“time”).select();

return;

}

else {

$time=$time.parseInt();

if ($mod_time==”mod_minute”) { $time=$time*60; }

}

getObject(“time”).disabled=true;

getObject(“mod_time”).disabled=true;

chStatus(“operation”,true);

getObject(“StartButton”).disabled=true;

getObject(“StopButton”).disabled=false;

Timer_Kernel();

}

function OperateWin32($DownFlag) {

$OS_Pro=GetObject(“WinMgmts:{(shutdown)}//https://www.jb51.net/article/root/cimv2”).ExecQuery(“select * from win32_operatingsystem where primary=true”);

for ($e=new Enumerator($OS_Pro);!$e.atEnd();$e.moveNext()) {

$getProcess=$e.item()

$getProcess.win32shutdown($DownFlag);

}

}

function ResponseKeyPress() {

if (event.keyCode==13) { event.keyCode=9; }

}

//–>

设定时间:

功能选择:

重启

关机

作者:黑虾

© 版权声明

相关文章