Windows2000怎样实现重启和关机?

lichp 2001-04-15 07:49:00
我在WIN ME里一切正常的程序,到WIN2000里却不能正常重启和关机了,只有注消还有用。看书,好像说要取得什么权力似的。倒底应该怎样实现啊?
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
universe 2001-04-16
  • 打赏
  • 举报
回复
Windows2000 自动关机函数

function Execute:boolean;
const
ADJUST_PRIV = TOKEN_QUERY or TOKEN_ADJUST_PRIVILEGES;
SHTDWN_PRIV = 'SeShutdownPrivilege';
PRIV_SIZE = sizeOf(TTokenPrivileges);
var
Len: DWORD;
TokenPriv, Dummy: TTokenPrivileges;
Token: THandle;

Text,
Machine:array [0..128] of Char;
Force,Reboot:boolean;

Error:integer;
FMachineName:String;
FMessage:String;

begin
error:=0;
begin
// Get a token for this process.

// Delphi2:
//if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, @Token) then
if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, Token) then
Error:=Error or 4;
{ ShowMessage('OpenProcessToken failed');}

// Get the LUID for the shutdown privilege.
if not LookupPrivilegeValue(nil, SHTDWN_PRIV,TokenPriv.Privileges[0].Luid) then
Error:=Error or 8;
{ShowMessage('LookupPrivilegeValue failed');}

// Adjust shutdown privilege for this process.
TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
TokenPriv.PrivilegeCount := 1; // One privilege to set
if not AdjustTokenPrivileges(Token, false, TokenPriv, PRIV_SIZE,Dummy, Len) then
Error:=Error or 16;
{ShowMessage('AdjustTokenPrivileges failed');}

StrPCopy(Text,FMessage);
StrPCopy(Machine,FMachineName);

{ if (shoForce in FOptions) then Force:=true
else Force:=false;
if (shoReboot in FOptions)then Reboot:=true
else Reboot:=false;}
InitiateSystemShutDown (Machine,Text,5,True,True);
end;
Kingron 2001-04-16
  • 打赏
  • 举报
回复
用了下面的函数,就可以用ExitWindow......关机了。这个问题回答过的,下面的代码是以前的贴子中Copy来的。
procedure 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;
lichp 2001-04-16
  • 打赏
  • 举报
回复
谢谢大家,我回去试试!
「已注销」 2001-04-15
  • 打赏
  • 举报
回复
需要关机权限

用Administrator登陆进行用户管理

一看便知
GoodHope 2001-04-15
  • 打赏
  • 举报
回复
至少要有Power User才有权关机。

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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