Programación General > C++ Builder

 Re: apagar windows con c++ builder 5

(1/1)

carlos_lue:
hola
me podrian decir como se puede apagar el windows desde una aplicacion en c++ builder 5.

¿Cual seria el codigo?

si me pueden ayudar gracias..

_Viktor:
Todo depende, que windows??? 95/98/me o nt/2000/xp, ya que el primer grupo se apaga de una forma y el segundo de otra...


 
--- Código: Text --- bool apagarWindows(void){    OSVERSIONINFO osvi;    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);    GetVersionEx( &osvi );    if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)    {        //--- Si estamos en NT/2000/XP obtenemos el permiso necesario del sistema         HANDLE hToken;        TOKEN_PRIVILEGES tkp;         if (!OpenProcessToken(GetCurrentProcess(),                TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))            return false;         LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);         tkp.PrivilegeCount = 1;        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;         AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);         if (GetLastError() != ERROR_SUCCESS)            return false;    }     //--- Apagamos     if (!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0))        return false;     return true;}      
Eso lo hace en ambos sistemas...

Saludos

Navegación

[0] Índice de Mensajes

Ir a la versión completa