Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 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
14-92249
Омлет
2003-08-09 00:30
2003.08.28
Palladin, с днём рождения!


3-92082
Andrey_1
2003-08-01 10:19
2003.08.28
как программно переключить DBEdit от 1го ист. данных к другому


14-92218
SPeller
2003-08-10 15:31
2003.08.28
Test


1-92095
REP
2003-08-14 07:47
2003.08.28
Добавление узла (Child) в TTreeView в произвольном месте


8-92119
BDRON
2003-05-03 17:43
2003.08.28
Оболчка для mp3 шек





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский