DELPHI对计算机的重新启动,关机操作
来源:互联网 发布:手机淘宝2017官方版 编辑:程序博客网 时间:2024/05/16 13:53
if Application.MessageBox('确定關机?','確認關閉電腦',MB_YESNO )=IDYES then
begin
if RadioButton1.Checked=true then
ExitWindowsEx(EWX_LOGOFF,0) //以其他用戶身份登錄
else if RadioButton2.Checked=true then
ExitWindowsEx(EWX_SHUTDOWN,1) //安全關机
else if RadioButton3.Checked=true then
ExitWindowsEx(EWX_REBOOT,2) //重新啟動計算机
else if RadioButton4.Checked=true then
ExitWindowsEx(EWX_FORCE,4) //強行關机
else if RadioButton5.Checked=true then
ExitWindowsEx(EWX_POWEROFF,8); //關閉係統並關閉電源
end;
procedure tform1.ShutDown;
procedure AdjustToken(); //获取关机控制权
var
hdlProcessHandle, hdlTokenHandle, lBufferNeeded: Cardinal;
tmpLuid: Int64;
//tkpPrivilegeCount: Int64;
tkp, tkpNewButIgnored: TOKEN_PRIVILEGES;
Privilege: array[0..0] of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess;
OpenProcessToken(hdlProcessHandle,
(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),
hdlTokenHandle);
// Get the LUID for shutdown privilege.
LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
Privilege[0].Luid := tmpLuid;
Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1; // One privilege to set
tkp.Privileges[0] := Privilege[0];
// Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges(hdlTokenHandle,
False,
tkp,
Sizeof(tkpNewButIgnored),
tkpNewButIgnored,
lBufferNeeded);
end;
begin
AdjustToken;
case send of
1: ExitWindowsEx(EWX_FORCE, 0); //在紧急情况下强制关机。 ;
2: ExitWindowsEx(EWX_LOGOFF, 0); //以其他用户身份登录。 ;
3: ExitWindowsEx(EWX_POWEROFF, 0); //关闭系统并关闭电源。
4: if application.MessageBox('是否重新启动', '重启计算机提示框', 1+48)=1 then //idok
begin
showmessage('reboot');
ExitWindowsEx(EWX_REBOOT, $FFFF); //重启操作系统
end
else
exit;
5: if application.MessageBox('是否关闭', '关闭计算机提示框', 1+48)=1 then //idok
begin
showmessage('close');
ExitWindowsEx(EWX_SHUTDOWN, $FFFF); //关机;
end
else
exit;
else
EXIT;
end;
end;
调用方法如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
send:=3;
ShutDown;
end;
- DELPHI对计算机的重新启动,关机操作
- delphi 关机 重新启动 注销 Windows
- 然后对当前快照"关机",再重新启动快照的操作系统就可以了
- WinCE下面的关机,重新启动和冷启动
- 如何控制Windows的关机或重新启动
- 常用的关机和重新启动命令
- Delphi对数据库的操作
- Delphi 对 Excel 的操作
- delphi 对excel 的操作
- 计算机关机操作工具实现
- 重新启动计算机
- 重新启动计算机
- “安装程序检测到计算机重新启动操作可能处于挂起状态”的解决方法
- “安装程序检测到计算机重新启动操作可能处于挂起状态”的解决方法
- 某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机
- 以前的某个程序安装在计算机上创建挂起文件操作,运行安装程序之前必须重新启动计算机
- 重新启动计算机失败和重装系统的解决
- 安装sqlserver2008,重新启动计算机不通过的解决办法
- 谈谈本科生和研究生的差距
- 十则故事,一场精彩管理学课程
- 为什么需要PKI
- [转贴]Tomcat类加载机制
- Sony中国十周年庆蹭饭之旅
- DELPHI对计算机的重新启动,关机操作
- 2006-12-28 圣诞与元旦之间
- 给Source Insight做个外挂系列之三--构建外挂软件的定制代码框架
- ReferenceEquals, == , Equals 比较
- 微视频与注意力经济
- TWebBrowser编程
- 实现自定义page基类时需要注意的地方
- [翻译] Effective C++, 3rd Edition, Item 51: 编写 new 和 delete 时要遵守惯例
- Log4cpp 中的跨平台类库