Форум: "Система";
Текущий архив: 2003.08.28;
Скачать: [xml.tar.bz2];
ВнизНе работает ExitWindowsEx(EWX_FORCE+EWX_REBOOT,0) Найти похожие ветки
← →
Федя (2003-06-10 15:48) [0]Наколько я понял для того чтобы это заработало программе нужно открыть какойто token, тоесть получить права.
Подскажите как это сделать.
← →
Song (2003-06-10 15:51) [1]В FAQ написано.
← →
max2057 (2003-06-12 13:53) [2]Вот те юнит.
unit secutil;
interface
uses Windows ;
const
{ Project JEDI Code Library (JCL) }
SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";
SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
SE_TCB_NAME = "SeTcbPrivilege";
SE_SECURITY_NAME = "SeSecurityPrivilege";
SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
SE_BACKUP_NAME = "SeBackupPrivilege";
SE_RESTORE_NAME = "SeRestorePrivilege";
SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
SE_DEBUG_NAME = "SeDebugPrivilege";
SE_AUDIT_NAME = "SeAuditPrivilege";
SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege";
SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
SE_UNDOCK_NAME = "SeUndockPrivilege";
SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
function EnableProcessPrivilege(const Enable: Boolean; const Privilege: string): Boolean;
implementation
function EnableProcessPrivilege(const Enable: Boolean; const Privilege: string): Boolean;
const
PrivAttrs: array [Boolean] of DWORD = (0, SE_PRIVILEGE_ENABLED);
var
Token: THandle;
TokenPriv: TTokenPrivileges;
begin
Result := False;
if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, Token) then
begin
TokenPriv.PrivilegeCount := 1;
LookupPrivilegeValue(nil, PChar(Privilege), TokenPriv.Privileges[0].Luid);
TokenPriv.Privileges[0].Attributes := PrivAttrs[Enable];
AdjustTokenPrivileges(Token, False, TokenPriv, SizeOf(TokenPriv),
nil, PDWord(nil)^);
Result := GetLastError = ERROR_SUCCESS;
CloseHandle(Token);
end;
end;
end.
а вот пример
secutil.EnableProcessPrivilege(true,SE_SHUTDOWN_NAME);
ExitWindowsEx(EWX_FORCE or EWX_POWEROFF,0);
( false,SE_SHUTDOWN_NAME) Вот те юнит.
unit secutil;
interface
uses Windows ;
const
{ Project JEDI Code Library (JCL) }
SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";
SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
SE_TCB_NAME = "SeTcbPrivilege";
SE_SECURITY_NAME = "SeSecurityPrivilege";
SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
SE_BACKUP_NAME = "SeBackupPrivilege";
SE_RESTORE_NAME = "SeRestorePrivilege";
SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
SE_DEBUG_NAME = "SeDebugPrivilege";
SE_AUDIT_NAME = "SeAuditPrivilege";
SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege";
SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
SE_UNDOCK_NAME = "SeUndockPrivilege";
SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
function EnableProcessPrivilege(const Enable: Boolean; const Privilege: string): Boolean;
implementation
function EnableProcessPrivilege(const Enable: Boolean; const Privilege: string): Boolean;
const
PrivAttrs: array [Boolean] of DWORD = (0, SE_PRIVILEGE_ENABLED);
var
Token: THandle;
TokenPriv: TTokenPrivileges;
begin
Result := False;
if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, Token) then
begin
TokenPriv.PrivilegeCount := 1;
LookupPrivilegeValue(nil, PChar(Privilege), TokenPriv.Privileges[0].Luid);
TokenPriv.Privileges[0].Attributes := PrivAttrs[Enable];
AdjustTokenPrivileges(Token, False, TokenPriv, SizeOf(TokenPriv),
nil, PDWord(nil)^);
Result := GetLastError = ERROR_SUCCESS;
CloseHandle(Token);
end;
end;
end.
а вот пример
secutil.EnableProcessPrivilege(true,SE_SHUTDOWN_NAME);
ExitWindowsEx(EWX_FORCE or EWX_POWEROFF,0);
secutil.EnableProcessPrivilege(false,SE_SHUTDOWN_NAME);}
← →
Sliski Slimak (2003-06-12 14:31) [3]А можно просто через ShellExecute юзать X:\windows\shutdown.exe
Страницы: 1 вся ветка
Форум: "Система";
Текущий архив: 2003.08.28;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.006 c