哪位兄弟知道win2000下关机,重启动如何搞定啊??在线等!!!

hvlm 2004-01-12 09:03:27
据说要实现什么权限吧,引用的API很麻烦,哪位有过有现成的,多谢了!!
...全文
110 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
eytech 2004-06-29
  • 打赏
  • 举报
回复
var
Form1: TForm1;

implementation

{$R *.dfm}

procedure AdjustToken();
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
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;
procedure ShutDown(uFlags: Cardinal);
begin
AdjustToken;
//ExitWindowsEx(EWX_LOGOFF , 0);
//ExitWindowsEx(EWX_SHUTDOWN, 0);
//ExitWindowsEx(EWX_REBOOT , 0);
//ExitWindowsEx(EWX_FORCE , 0);
ExitWindowsEx(uFlags, 0);
//ExitWindowsEx(EWX_FORCEIFHUNG , 0);
{EWX_FORCE or EWX_SHUTDOWN,0}
end;




procedure TForm1.BitBtn2Click(Sender: TObject);//注销
begin
ShutDown(EWX_FORCE or EWX_LOGOFF);
end;

procedure TForm1.BitBtn3Click(Sender: TObject);//关机
begin
ShutDown(EWX_FORCE or EWX_POWEROFF);
end;

procedure TForm1.BitBtn4Click(Sender:TObjedt);//重启
begin
ShutDown(EWX_FORCE OR EWX_REBOOT);
end;
startjoy 2004-06-29
  • 打赏
  • 举报
回复
MP_Reset: //--重启动
if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
ExitWindowsEx(EWX_REBOOT, 0)
else
begin
SetPrivilege('SeShutdownPrivilege', True);
if not ExitWindowsEx(EWX_REBOOT + EWX_FORCE, 0) then
SetPrivilege('SeShutdownPrivilege', False);
end;

MP_Down: //--关机
if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
ShellExecute(handle, 'open', 'RUNDLL32.EXE', 'user.exe,ExitWindows', nil, SW_ShowNormal)
else
begin
SetPrivilege('SeShutdownPrivilege', True);
if not ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE+EWX_POWEROFF, 0) then
SetPrivilege('SeShutdownPrivilege', False);
end;
bphantom 2004-06-21
  • 打赏
  • 举报
回复
Function MySystemShutdown():boolean;
var
hToken:THANDLE;
tkp:TOKEN_PRIVILEGES;
zero : DWORD;
begin
// Get a token for this process.

if not(OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES and TOKEN_QUERY, hToken)) then
result := FALSE ;

// Get the LUID for the shutdown privilege.

//LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME ,@tkp.Privileges[0].Luid);
LookupPrivilegeValue(nil, 'SeSecurityPrivilege' ,tkp.Privileges[0].Luid);

tkp.PrivilegeCount := 1; // one privilege to set
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

// Get the shutdown privilege for this process.

//AdjustTokenPrivileges(hToken, false, tkp, 0,nil, 0);
AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), nil, zero );

if (GetLastError() <> ERROR_SUCCESS) then
result := FALSE;

// Shut down the system and force all applications to close.
//EWX_POWEROFF,EWX_LOGOFF,EWX_SHUTDOWN
if not(ExitWindowsEx(EWX_REBOOT and EWX_FORCE, 0)) then
result := FALSE;

result := TRUE;
end;
ly_liuyang 2004-01-12
  • 打赏
  • 举报
回复
tanxj(明剑) 的是最好用的

好象是我写的代码呀,呵呵:)
kw123 2004-01-12
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2511/2511952.xml?temp=.1286432
cumtyangjin 2004-01-12
  • 打赏
  • 举报
回复
这么多兄弟都说了,我就不多说了
aushqh 2004-01-12
  • 打赏
  • 举报
回复
如果重启又要自动登陆的话,需要修改注册表里面的东西。(在CurrentVersion\winlogon下添加相应的键值)
aushqh 2004-01-12
  • 打赏
  • 举报
回复
关机:ExitWindowsEx(EWX_SHUTDOWN, $FFFF);

重启:ExitWindowsEx(EWX_REBOOT,$FFFF);

注销:ExitWindowsEx(EWX_LOGOFF, $FFFF);

甜而不腻 2004-01-12
  • 打赏
  • 举报
回复
要自己动手查,网上很多这样的东西。
WWWWA 2004-01-12
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
procedure AdjustToken;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.AdjustToken();
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkpPrivilegeCount : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
AdjustToken;
ExitWindowsEx((EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), $FFFF);
end;

end.

tanxj 2004-01-12
  • 打赏
  • 举报
回复
if true,关机,false 重启
lgqTiger 2004-01-12
  • 打赏
  • 举报
回复
你式试在CSDN中查找一下
很多人提过这个问题!
tanxj 2004-01-12
  • 打赏
  • 举报
回复
procedure PowerOff(Force:boolean=false);
var
hToken : THandle;
tkp : TTokenPrivileges;
tkpo : TTokenPrivileges;
zero : DWORD;
begin
if Win32Platform=VER_PLATFORM_WIN32_NT then // we've got to do a whole buch of things
begin
zero := 0;
if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
begin
MessageBox( 0, 'PowerOff Error', 'OpenProcessToken() Failed', MB_OK );
Exit;
end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)

// SE_SHUTDOWN_NAME
if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then
begin
MessageBox( 0, 'PowerOff Error', 'LookupPrivilegeValue() Failed', MB_OK );
Exit;
end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );
if Boolean( GetLastError() ) then
begin
MessageBox( 0, 'PowerOff Error', 'AdjustTokenPrivileges() Failed', MB_OK );
Exit;
end // if Boolean( GetLastError() )
else if Force then
ExitWindowsEx( EWX_POWEROFF, 0 )
else ExitWindowsEx( EWX_REBOOT, 0 );
end // if OSVersion = 'Windows NT'
else // just shut the machine down
if Force then ExitWindowsEx( EWX_POWEROFF, 0 )
else ExitWindowsEx( EWX_REBOOT, 0 );
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧