necesito apagar mi pc por codigo
he intentado con las funciones API
\'ExitWindowsEx\' Con sus distintos parametros, pero no funciona, luego intente con la funcion
ExitWindows(0,0) pero igual no funciona.
deseo que al pulsar un boton ,en mi aplicacion,
se cierre el sistema operativo y luego se vea el cartel de \'Ahora puede apagar su equipo\'
desde ya muchas gracias
\'ExitWindowsEx\' Con sus distintos parametros, pero no funciona, luego intente con la funcion
ExitWindows(0,0) pero igual no funciona.
deseo que al pulsar un boton ,en mi aplicacion,
se cierre el sistema operativo y luego se vea el cartel de \'Ahora puede apagar su equipo\'
desde ya muchas gracias
Hola, tenia esto tal vez te sirva...
// Devuelve false si ha ocurrido alg煤n problema
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;
}
Saludos!
_Viktor
// Devuelve false si ha ocurrido alg煤n problema
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;
}
Saludos!
_Viktor
