unit zhuxiao;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shlobj, StdCtrls,ShellAPI;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
//function exitwindowsex(uflags,dwreserved:cardinal):longbool;external user32 name 'ExitWindowsEx';
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
exitwindowsex(ewx_force,0);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
exitwindowsex(ewx_reboot,0);//重起
exitwindowsex(ewx_shutdown,0);//重起end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shlobj, StdCtrls,ShellAPI;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
//function exitwindowsex(uflags,dwreserved:cardinal):longbool;external user32 name 'ExitWindowsEx';
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
exitwindowsex(ewx_force,0);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
exitwindowsex(ewx_reboot,0);//重起
exitwindowsex(ewx_shutdown,0);//重起end;end.
解决方案 »
- 有对Stereoscopic Player这个3D播放软件比较熟悉的吗?
- VC++ 中的&符号 对应的是Delphi中的哪个符号??
- l如何对包括自动加1字段的数据表添加新记录
- delphi中不通过idhttp控件来实现http代理连接的代码?
- Error reading from socket如何解决,出现错误的原因
- dbexpress的TSQLCONNECTION的连接Error Mapping Failed问题
- 关于抓屏的一些问题--需要真正的专家
- 怎么动态屏蔽PageControl1的第一个页面?
- 在哪儿能下载到gl32.dll?
- 关于Delphi 5中Excel Server的用法
- 急等,高手请进!!使用label定时显示数据闪烁问题
- 急等,高手请进!!使用label定时显示数据闪烁问题
var
hProcess,hAccessToken:THandle;
LUID_AND_ATTRIBUTES:TLUIDAndAttributes;
TOKEN_PRIVILEGES: TTokenPrivileges;
BufferIsNull:DWORD;
Const
SE_SHUTDOWN_NAME='SeShutdownPrivilege';
begin
hProcess:=GetCurrentProcess();
OpenProcessToken(hprocess,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,hAccessToken);
LookupPrivilegeValue(Nil,SE_SHUTDOWN_NAME,LUID_AND_ATTRIBUTES.Luid);
LUID_AND_ATTRIBUTES.Attributes:=SE_PRIVILEGE_ENABLED;
TOKEN_PRIVILEGES.PrivilegeCount:=1;
TOKEN_PRIVILEGES.Privileges[0]:=LUID_AND_ATTRIBUTES;
BufferIsNull:=0;
AdjustTokenPrivileges(hAccessToken,False,TOKEN_PRIVILEGES,sizeof(TOKEN_PRIVILEGES),Nil,BufferIsNull);
ExitWindowsEx(EWX_POWEROFF, 0);
ShutDownSystem:=True;
end;
这个可以用以2K以上,
function ShutMeDown:string;
var
hToken : THandle;
tkp,p : TTokenPrivileges;
RetLen : DWord;
ExReply: LongBool;
Reply : DWord;
begin
case Win32Platform of
VER_PLATFORM_WIN32_WINDOWS: //***Windows 9x/ME***//
begin
ExReply:= ExitWindowsEx(EWX_POWEROFF or EWX_SHUTDOWN or EWX_FORCE,0);
if ExReply then
Result:='Shutdown Initiated'
else
Result:='Shutdown failed with ' + IntToStr(GetLastError);
end;
VER_PLATFORM_WIN32_NT: //***Windows NT/2000/XP***//
begin
if OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY,hToken) then
begin
if
LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid) then
begin
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes :=
SE_PRIVILEGE_ENABLED;AdjustTokenPrivileges(hToken,False,tkp,SizeOf(TTokenPrivileges),p,RetLen);
Reply := GetLastError;
if Reply = ERROR_SUCCESS then
begin
ExReply:= ExitWindowsEx(ewx_shutdown or EWX_POWEROFF, 0);
if ExReply then
Result:='Shutdown Initiated'
else
Result:='Shutdown failed with ' + IntToStr(GetLastError);
end;
end;
end;
end; //end case
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
Const
SE_SHUTDOWN_NAME='SeShutdownPrivilege';
var
hProcess,hAccessToken:Thandle;
Luid_and_attributes:Tluidandattributes;
token_privileges:TTokenPrivileges;
BufferIsNull:Dword;
begin
hProcess:=GetCurrentProcess ;
OpenProcessToken(hprocess,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,hAccessToken);
LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME,Luid_and_attributes.luid);
luid_and_attributes.Attributes :=SE_PRIVILEGE_ENABLED;
token_privileges.PrivilegeCount :=1;
token_privileges.Privileges[0]:=Luid_and_attributes;
BufferIsNull :=0;
adjusttokenprivileges(haccesstoken,false,token_privileges,sizeof(token_privileges),nil,BufferIsNull);
case RadioGroup1.ItemIndex of
0:win32check(ExitWindows(0,0));
1:win32check(ExitWindowsEx(EWX_LOGOFF,0));
2:win32check(ExitWindowsEx(EWX_REBOOT,0));
3:win32check(ExitWindowsEx(EWX_SHUTDOWN,0));
end;
end;