关闭系统问题?(20分)

  • 主题发起人 主题发起人 failam
  • 开始时间 开始时间
F

failam

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我用exitwindowsex(ewx_shutdown,0)时会报1314错误(无权限)。
用exitwindowsex(ewx_force,0)能正常调用。
我用的是windows2000,delphi6,用户是administrator.
 
help me...............
 
在windows2000下关机需要权限!
你需要Win2000下关机的代码可以在论坛里搜索一下!已经有标准答案了!
 
我还没看懂!
关机代码是指什么?
 
SE_SHUTDOWN_NAME 为Win2000下要求的关机权限!

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;
 
EWX_SHUTDOWN

Shuts down the system to a point at which it is safe to turn off the power.
All file buffers have been flushed to disk, and all running processes have
stopped.

Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege.
For more information, see the following Remarks section.

Windows 95: Security privileges are not supported or required.

Remarks

The ExitWindowsEx function returns as soon as it has initiated the shutdown.
The shutdown or logoff then proceeds asynchronously.
During a shutdown or log-off operation, applications that are shut down are
allowed a specific amount of time to respond to the shutdown request.
If the time expires, Windows displays a dialog box that allows the user to
forcibly shut down the application, to retry the shutdown, or to cancel the
shutdown request. If the EWX_FORCE value is specified, Windows always forces
applications to close and does not display the dialog box.

The ExitWindowsEx function sends a separate notification message,
CTRL_SHUTDOWN_EVENT or CTRL_LOGOFF_EVENT as the situation warrants,
to console processes. A console process routes these messages to its
HandlerRoutine functions, which are added and removed by calls to the
SetConsoleCtrlHandler function. ExitWindowsEx sends these notification
messages asynchronously; thus, an application cannot assume that the console
notification messages have been handled when a call to ExitWindowsEx returns.

Windows NT: To shut down or restart the system, the calling process must use
the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege.
For more information about security privileges, see Privileges.
Windows 95: Security privileges are not supported or required.
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
889
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部