asp.net 自动关机的代码
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using system.runtime.interopservices;
using system.diagnostics;namespace shutdown
{
public partial class shutdownform : form
{public shutdownform()
{
initializecomponent();
}[structlayout(layoutkind.sequential)]
public struct lastinputinfo
{
public uint cbsize;
public uint dwtime;
};[dllimport("user32.dll")]
private static extern bool getlastinputinfo(ref lastinputinfo ii);
public long getidletime()
{
lastinputinfo lastinput = new lastinputinfo();
lastinput.cbsize = (uint)system.runtime.interopservices.marshal.sizeof(lastinput);if (getlastinputinfo(ref lastinput))
{
long el = lastinput.dwtime;
long ui = (environment.tickcount - el);// overflow
if (ui ui = ui + uint.maxvalue + 1;return ui;
}
else
{
throw new applicationexception("timespan");
}}
private void timer1_tick(object sender, eventargs e)
{
if( getidletime() > 5000)
{
timer1.enabled = false;
messagebox.show("5秒到了"); //无具体意义,方便调试而已
executecmd("shutdown.exe -s -f"); //执行关机命令
}
}public void executecmd(string command)
{
process proc = new process();
proc.startinfo.filename = "cmd.exe";
proc.startinfo.useshellexecute = false;
proc.startinfo.redirectstandarderror = true;
proc.startinfo.redirectstandardinput = true;
proc.startinfo.redirectstandardoutput = true;
proc.startinfo.createnowindow = false;
proc.start();
proc.standardinput.writeline(command);
proc.standardinput.writeline("exit");
}}
}
//方法二
if lesssecond process.start("shutdown.exe", " -s -t 0");
%>
洋果子店rose最新版本
洋果子店最新版是一款十分容易让人垂涎的开店经营类手游。游戏玩
明日大亨最新版
明日大亨手游,一个非常经典有趣的模拟经营类型的商战手游,在游
早安我的少年日服最新版2024
早安我的少年日服是一款治愈恋爱手游,清新明亮的游戏画面,让你
我的世界基岩版1.16正式版
我的世界基岩版是一款模拟经营手游,游戏采用的是经典像素玩法,
早安我的少年最新版2024
早安我的少年是一款养成恋爱手游,在这款游戏中,玩家们将可以体