C++ Programm - Shutdown win2k

Discussion in 'C++' started by Andreas Horneff, Aug 16, 2004.

  1. Hi at all,

    I've got this function (written in BC++)

    bool TShutdown::MySystemShutdown()
    {
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    // Get a token for this process.

    if (!OpenProcessToken(GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    return( FALSE );

    // 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);

    if (GetLastError() != ERROR_SUCCESS)
    return FALSE;

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

    if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
    return FALSE;

    return TRUE;
    }

    Now my problem. When I execute this funtion on my Laptop, running with
    WinXP, my Laptop shuts
    down and switchs off.

    On my other system, running with win2k, win2k shut down, but the PC didn't
    switch off. My Mainboard
    supports this function. When I click at 'Start', 'Shutdown', the PC switchs
    off, after shutdown. Why
    dosen't it switch off, when I run my Function?! Can anyone help me?
    Or can anyone tell me an other way, to realize that?!

    THX a lot!!!

    (The function isn't written by myself, I found it at the WWW)

    Sorry for my bad english...

    Andreas
     
    Andreas Horneff, Aug 16, 2004
    #1
    1. Advertising

  2. Andreas Horneff

    lallous Guest

    "Andreas Horneff" <> wrote in message
    news:cfq172$f6r$02$-online.com...
    > Hi at all,
    >
    > I've got this function (written in BC++)
    >
    > bool TShutdown::MySystemShutdown()
    > {
    > HANDLE hToken;
    > TOKEN_PRIVILEGES tkp;
    >
    > // Get a token for this process.
    >
    > if (!OpenProcessToken(GetCurrentProcess(),
    > TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    > return( FALSE );
    >
    > // 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);
    >
    > if (GetLastError() != ERROR_SUCCESS)
    > return FALSE;
    >
    > // Shut down the system and force all applications to close.
    >
    > if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
    > return FALSE;
    >
    > return TRUE;
    > }
    >
    > Now my problem. When I execute this funtion on my Laptop, running with
    > WinXP, my Laptop shuts
    > down and switchs off.
    >
    > On my other system, running with win2k, win2k shut down, but the PC didn't
    > switch off. My Mainboard
    > supports this function. When I click at 'Start', 'Shutdown', the PC

    switchs
    > off, after shutdown. Why
    > dosen't it switch off, when I run my Function?! Can anyone help me?
    > Or can anyone tell me an other way, to realize that?!
    >
    > THX a lot!!!
    >
    > (The function isn't written by myself, I found it at the WWW)
    >
    > Sorry for my bad english...
    >
    > Andreas
    >
    >


    Hello Andreas,

    I would suggest that you re-post this question to
    microsoft.public.win32.programmer.kernel.

    Here C++ (not related to OS) topics are discussed.

    --
    Elias
     
    lallous, Aug 16, 2004
    #2
    1. Advertising

  3. Andreas Horneff

    Jack Klein Guest

    Jack Klein, Aug 17, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Freddy Fischer
    Replies:
    1
    Views:
    316
    Natty Gur
    Oct 23, 2003
  2. AlexPain

    Java Programm into Systray

    AlexPain, Jul 30, 2003, in forum: Java
    Replies:
    5
    Views:
    1,500
    Eugene Toporov
    Aug 5, 2003
  3. Romeo
    Replies:
    3
    Views:
    373
    Mickey Segal
    Nov 13, 2003
  4. Excluded_Middle

    Sheck this simple programm

    Excluded_Middle, Jul 13, 2004, in forum: Java
    Replies:
    7
    Views:
    439
    Roedy Green
    Jul 14, 2004
  5. Sam
    Replies:
    1
    Views:
    496
    Andrew Thompson
    Nov 10, 2004
Loading...

Share This Page