网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > DELPHI > 正文
Delphi NT/XP中的关闭计算机,重新登陆的实现
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/12
下载{$ArticleTitle}原创论文样式

NT中的关闭计算机,重新登陆的实现

在NT中要实现以上的功能,首先必须获得SE_SHUTDOWN_NAME权限后,才能调用ExitWindowsEx;这是和Windows95的不同

//iFlags:

// one of the following must be specified

// EWX_LOGOFF

// EWX_REBOOT

// EWX_SHUTDOWN

// following attributes may be combined with above flags

// EWX_POWEROFF

// EWX_FORCE : terminate processes

function WinExitInNT( iFlags : integer ) : boolean;

begin

Result := True;

if( SetPrivilege( ''SeShutdownPrivilege''

True ) )then

begin

if( not ExitWindowsEx( iFlags

0 ) )then

begin

Result := False;

end;

SetPrivilege( ''SeShutdownPrivilege''

False )

end

else begin

// handle errors

Result := False;

end;

end;

//Enabled or DisEnabled the SE_SHUTDOWN_NAME privilege

//sPrivilegeName:

// ''SE_SHUTDOWN_NAME''

//bEnabled :

// Enabled or DisEnabled ''SE_SHUTDOWN_NAME'' privilege

function SetPrivilege(sPrivilegeName : string;

bEnabled : boolean )

: boolean;

var

TPPrev

TP : TTokenPrivileges;

Token : THandle;

dwRetLen : DWord;

begin

Result := False;

//opens the access token associated with a process.

OpenProcessToken(

GetCurrentProcess

//handle to process

TOKEN_ADJUST_PRIVILEGES //Required to change the privileges specified in an access token.

or TOKEN_QUERY

//Required to query the contents of an access token.

Token);

TP.PrivilegeCount := 1;

//retrieves the locally unique identifier (LUID) used on a specified system to

//locally represent the specified privilege name.

if( LookupPrivilegeValue(

Nil

//attempts to find the privilege name on the local system.

PChar( sPrivilegeName )

// address of string specifying the privilege

TP.Privileges[ 0 ].LUID ) // address of locally unique identifier

)then

begin

if( bEnabled )then //Give this privileges

begin

TP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;

end

else begin //NOT Give this privileges

TP.Privileges[ 0 ].Attributes := 0;

end;

dwRetLen := 0;

//enables or disables privileges in the specified access token.

Result := AdjustTokenPrivileges(

Token

// handle to token that contains privileges

False

//modifies privileges

TP

// pointer to new privilege information

SizeOf( TPPrev )

// size

in bytes

of the TPPrev buffer

TPPrev

// receives original state of changed privileges

dwRetLen // receives required size of the TPPrev buffer

);

end;

CloseHandle( Token );

end;

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号