Вырубить комп без логона

From
Alexander Schmidt (2:5036/18.12)
To
Vlad Foltz
Date
2002-04-15T23:37Z
Area
SU.WINDOWS.NT.PROG
(14 Apr 02) Vlad Foltz sagen fur All...


=== Cut ===

#define _WIN32_WINNT 0x0500

#include <stdio.h>
#include <windows.h>

int main(int argc, char* argv[])
{
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    printf("\nWaiting for all processes to complete their immediate needs (3
sec)...\n");

    Sleep(3000);

    printf("Forcing system reboot...\n");

    // Get a token for this process.

    if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    printf("Error OpenProcessToken\n");

    // Get the LUID for the shutdown privilege.

    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
        &tkp.Privileges[0].Luid);

    tkp.PrivilegeCount = 1;  // one privilege to set
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    // Get the shutdown privilege for this process.

    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
        (PTOKEN_PRIVILEGES)NULL, 0);

    // Cannot test the return value of AdjustTokenPrivileges.

    if (GetLastError() != ERROR_SUCCESS)
        printf("Error AdjustTokenPrivileges");

    // Shut down the system and force all applications to close.

    if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
        printf("Error ExitWindowsEx");

    ExitWindowsEx(EWX_REBOOT | EWX_FORCEIFHUNG, 0);

    return 0;
}
=== Cut ===

 VF>     Пpивет, All !

 VF> Сабж не работает (все нужные привилегии нормально получаю).
 VF> ExitWindowsEx ошибки не возвращает, но эффекта никакого. А вот если
 VF> юзер залогинен - все работает. InitiateSystemShutdown работает, но не
 VF> вырубает питания на ATX, а надо.

 VF> P.S. w2k pro sp1
 VF> P.S.S. Саму "шутдаунилку" запускаю через "назначенные задания" из под
 VF> юзера с админскими правами.

 VF>        Ну пока, All.

 VF> vladislav_foltz@mail.ru
 VF> -+- GoldEd snapshot-2001.03.04.
 VF>  ? Origin: ########[OO]-[OO]-[OO]-[|+|+|>######### (2:5030/1015.8)
Respekt, Alexander

---
 * Origin: Основной тон жизни - это скука, впечатление чего-то с (2:5036/18.12)