Главная страница
    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-92232
Igor__
2003-08-09 15:31
2003.08.28
Мастера, а щас применяют 15bpp BITMAP


3-91982
Verg
2003-08-01 12:12
2003.08.28
Firebird 1.5 RCx & PHP


7-92281
msgipss
2003-06-11 10:08
2003.08.28
Программно отключить системный динамик


6-92144
DocSS
2003-06-19 19:15
2003.08.28
Заполнение html-форм через TWebBrowser?


4-92295
DmitryNekl
2003-06-26 14:27
2003.08.28
LockFile - вопрос чайника





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский