怎样实现定时关机? ( 积分: 50 )

  • 主题发起人 主题发起人 yuanxianer
  • 开始时间 开始时间
Y

yuanxianer

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个定时关机的程序, 应该这样做?请指点
 
我想做一个定时关机的程序, 应该这样做?请指点
 
//操作函數:注銷.重起.關機<br>procedure operatecomputer(statue:longword);<br>var<br>hToken:THandle;<br>tkp : TOKEN_PRIVILEGES;<br>ReturnLength : DWord;<br>begin<br>if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then<br>begin<br>application.Terminate;<br>end;<br>LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);<br>tkp.PrivilegeCount := 1;<br>tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;<br>ReturnLength :=0;<br>AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);<br>if (GetLastError() &lt;&gt; ERROR_SUCCESS) then<br>begin<br>application.Terminate;<br>end;<br>if (not ExitWindowsEx(statue, 0)) then<br>begin<br>application.Terminate;<br>end;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>s:string;<br>NTime,MTime,OnTime,OnTime1,Onreboot : String;<br>begin<br> &nbsp;s:=label12.Caption;<br> &nbsp;label12.Caption:=timetostr(StrToTime(S));<br> &nbsp;label10.Caption:=datetostr(date);<br> &nbsp;label12.Caption:=timetostr(time);<br> &nbsp;OnTime:=TimeToStr(DateTimePicker5.Time);<br> &nbsp;OnTime1:=TimeToStr(DateTimePicker6.Time);<br> &nbsp; NTime:=TimeToStr(DateTimePicker3.Time);<br> &nbsp; MTime:=TimeToStr(DateTimePicker4.Time);<br> &nbsp; Onreboot:=TimeToStr(DateTimePicker7.Time);<br> &nbsp;if (DateTimePicker5.Checked=true) and (DateTimePicker5.Enabled=true) then<br> &nbsp;if ontime=S then<br> &nbsp;begin<br> &nbsp; showmessage('你設定的時間已經到了!');<br> &nbsp;end;<br> &nbsp;if (DateTimePicker6.Checked=true) and (DateTimePicker6.Enabled=true) then<br> &nbsp;if ontime1=S then<br> &nbsp;begin<br> &nbsp; showmessage('時間過的好快啊,又到了!');<br> &nbsp;end;<br><br> &nbsp;if NTime=s then<br> &nbsp; begin<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_windows then<br> &nbsp; &nbsp; exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_NT then<br> &nbsp; &nbsp; operatecomputer(ewx_reboot); &nbsp; //ewx_reboot 重起&amp;#63236;<br> &nbsp; &nbsp; end;<br> &nbsp;if (MTime=s) and (DateTimePicker4.Enabled=true) then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_windows then<br> &nbsp; &nbsp; exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_NT then<br> &nbsp; &nbsp; operatecomputer(ewx_reboot); &nbsp; //ewx_reboot 重起&amp;#63236;<br> &nbsp; &nbsp; end;<br> &nbsp;if (DateTimePicker7.Checked=true) and (DateTimePicker7.Enabled=true) then<br> &nbsp;if Onreboot=s then<br> &nbsp; begin<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_windows then<br> &nbsp; &nbsp; exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_NT then<br> &nbsp; &nbsp; operatecomputer(ewx_poweroff); &nbsp; //ewx_logoff 關機<br> &nbsp; &nbsp; end;<br><br>end;
 
这里有个例程:<br>http://www.delphibox.com/article.asp?articleid=1540
 
兄弟,请加我QQ:38223756<br>我有一个自己做的程序,可以关机,重启,锁定,注销。在XP下完全没问题,不过我的不带定时,你自己加个吧,我想定时,是很好实现的。。。
 
我做了个程序已经实现了这个功能~我的QQ:38993286
 
procedure operatecomputer(statue:longword);<br>var<br>hToken:THandle;<br>tkp : TOKEN_PRIVILEGES;<br>ReturnLength : DWord;<br>begin<br>if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then<br>begin<br>application.Terminate;<br>end;<br>LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);<br>tkp.PrivilegeCount := 1;<br>tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;<br>ReturnLength :=0;<br>AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);<br>if (GetLastError() &lt;&gt; ERROR_SUCCESS) then<br>begin<br>application.Terminate;<br>end;<br>if (not ExitWindowsEx(statue, 0)) then<br>begin<br>application.Terminate;<br>end;<br>end;<br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>case radiogroup1.ItemIndex of<br>0: begin<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_windows then<br> &nbsp; &nbsp; exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_NT then<br> &nbsp; &nbsp; operatecomputer(ewx_poweroff); &nbsp; //ewx_logoff 为关机<br> &nbsp; &nbsp; end;<br>1: &nbsp; begin<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_windows then<br> &nbsp; &nbsp; exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_NT then<br> &nbsp; &nbsp; operatecomputer(ewx_reboot); &nbsp; //ewx_reboot 为重启<br> &nbsp; &nbsp; end;<br>2: &nbsp; begin<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_windows then<br> &nbsp; &nbsp; exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);<br> &nbsp; &nbsp; if win32platform =ver_platform_win32_NT then<br> &nbsp; &nbsp; operatecomputer(ewx_logoff); &nbsp; //ewx_logoff 为注销<br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp;end;<br>end;<br>要怎麼定時你自己解決了.
 
在98下比较简单,在nt、2000下要获得权限,楼上的各位已经写的很清楚了。
 
多人接受答案了。
 
后退
顶部