Q&A

  • 윈도우2000 종료시키기
안녕하세요



윈도우2000 서버를 쓰고 있는데요, 지정된 시각에 윈도우 종료하도록 하려고 하는데요,



일단 지정된 시각에 대한 것은 배제하고,



종료만이라도 되었으면 하는데요.



여기서 찾아본 소스로는 에러가 나네요.



여기에서 찾은 소스랑 에러구문 올릴께요.



빠른 답변 부탁드립니다. ^^;



var

PreviosPrivileges : ^TTokenPrivileges;

TokenPrivileges : TTokenPrivileges;

ProcessHandle : THandle;

tmp : Integer;

begin

if not OpenProcessToken( GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,ProcessHandle ) then

Exit;



LookupPrivilegeValue( '', 'SeShutdownPrivilege', TokenPrivileges.Privileges[0].Luid );

TokenPrivileges.PrivilegeCount := 1;

TokenPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

tmp := 0;

PreviosPrivileges := nil;

AdjustTokenPrivileges(ProcessHandle, False, TokenPrivileges, 0, PreviosPrivileges^, tmp);

if not GetLastError()=ERROR_SUCCESS then

Exit;

if not InitiateSystemShutdown( '', '', 0, True, True ) then

Exit;

TokenPrivileges.Privileges[0].Attributes := 0;

AdjustTokenPrivileges( ProcessHandle, False, TokenPrivileges, 0,PreviosPrivileges^, tmp );

end;



========================

에러구문

[Error] Unit1.pas(41): There is no overloaded version of 'AdjustTokenPrivileges' that can be called with these arguments

[Error] Unit1.pas(47): There is no overloaded version of 'AdjustTokenPrivileges' that can be called with these arguments

[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'







AdjustTokenPrivileges(ProcessHandle, False, TokenPrivileges, 0, PreviosPrivileges^, tmp);

이부분과



AdjustTokenPrivileges( ProcessHandle, False, TokenPrivileges, 0,PreviosPrivileges^, tmp );

이부분에서 에러가 났습니다.

1  COMMENTS
  • Profile
    이경문 2001.11.21 04:47
    도움이 될려나 모르겠네요. CPP로 작성된 건데...

    ----------- reboot.h -----------

    #ifndef __REBOOT_H__

    #define __REBOOT_H__



    void _Reboot(void);



    #endif // __REBOOT_H__



    ----------- reboot.cpp -----------

    #include "Reboot.h"



    void ShutDownNT();

    BOOL IsOsNT();



    void _Reboot(void)

    {

    if (IsOsNT())

    ShutDownNT(); // win nt or 2000

    else

    ExitWindowsEx( EWX_REBOOT, 0 );//win95,98,ME

    }



    void ShutDownNT()

    {

    HANDLE hToken; // handle to process token

    TOKEN_PRIVILEGES tkp; // pointer to token structure



    BOOL fResult; // system shutdown flag



    // Get the current process token handle so we can get shutdown

    // privilege.



    if (!OpenProcessToken(GetCurrentProcess(),

    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))

    ::MessageBox(NULL, "OpenProcessToken failed.", "Warning", MB_OK);



    // Get the LUID for 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 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)

    ::MessageBox(NULL, "AdjustTokenPrivileges enable failed.", "Warning", MB_OK);



    // Display the shutdown dialog box and start the time-out countdown.



    fResult = InitiateSystemShutdown(

    NULL, // shut down local computer

    "System rebooting.", // message to user

    0, // time-out period (<- 여기를 20 이라고 쓰면 20초 후 에 리부팅한다.)

    FALSE, // ask user to close apps

    TRUE); // reboot after shutdown



    if (!fResult)

    {

    ::MessageBox(NULL, "InitiateSystemShutdown failed.", "Warning", MB_OK);

    }



    // error string..

    //PrintCSBackupAPIErrorMessage(GetLastError());



    // Disable shutdown privilege.



    tkp.Privileges[0].Attributes = 0;

    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,

    (PTOKEN_PRIVILEGES) NULL, 0);



    if (GetLastError() != ERROR_SUCCESS)

    {

    ::MessageBox(NULL, "AdjustTokenPrivileges disable failed.", "Warning", MB_OK);

    }



    }



    BOOL IsOsNT()

    {

    //////////////////////////////

    // OS detection routine.



    OSVERSIONINFO version;

    /* First we have to find out which OS we are running on */

    version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    /* If we get and error, we can't continue. */



    // CString strplatformid;

    BOOL bNT = FALSE;



    if(GetVersionEx(&version))

    {

    DWORD dwplatformid = version.dwPlatformId;

    switch (version.dwPlatformId)

    {

    case VER_PLATFORM_WIN32s:

    // strplatformid.Format("Windows 3.1");

    bNT = FALSE;

    break;

    case VER_PLATFORM_WIN32_WINDOWS:

    if(version.dwMinorVersion == 0)

    {

    // strplatformid.Format("Windows 95");

    bNT = FALSE;

    }else if(version.dwMinorVersion > 0)

    {

    // strplatformid.Format("Windows 98");

    bNT = FALSE;

    }

    break;

    case VER_PLATFORM_WIN32_NT:

    // strplatformid.Format("Windows NT");

    bNT = TRUE;

    break;

    default:

    bNT = FALSE;

    break;

    }

    }

    return bNT;

    }