hOW TO MAKE A PROGRAM WHICH MAKES MY pC TO SHUTDOWN?

This is a discussion on hOW TO MAKE A PROGRAM WHICH MAKES MY pC TO SHUTDOWN? within the Windows Programming forums, part of the Platform Specific Boards category; how can I make a shutdown program??? in c++ (Borland 5.02)???...

  1. #1
    ALANAIR23
    Guest

    hOW TO MAKE A PROGRAM WHICH MAKES MY pC TO SHUTDOWN?

    how can I make a shutdown program??? in c++ (Borland 5.02)???

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230

    oh man...

    you're so damned lazy! This has been asked TWICE on the old board within a few days!! grrrr.....*calms himself down*

    http://cprogram.hypermart.net/cgi-bi...age=0&Session=

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    17

    Exclamation

    But it doesnt work u idiot!

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230

    oh well...

    I should probably never post so early in the morning anymore...

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    what erros does it give you, cuz I'm sure it works...

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    This will shutdown windows (only 9x). It must be compiled as a windows app not a console one -

    Code:
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    
    
        ExitWindowsEx(EWX_FORCE|EWX_SHUTDOWN,NULL);
    
        return 0;
    }

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    This is quoted from the Win32 API in Borland C++ 4.52 IDE. I've never used this as I usually have no need to actually shut down. Normally I use the ExitWindows function as my programs usually only require a reboot, not an actual shutdown.

    I'm not sure if it is good practice to quote from SDK's, but the explanation was far too lengthy so that is why I did.

    The ExitWindowsEx function can be used to shut down the system. Shutting down flushes file buffers to disk and brings the system to a condition in which it is safe to turn off the computer. The calling process must have the SE_SHUTDOWN_NAME privilege to shut down the system.

    The following example enables the SE_SHUTDOWN_NAME privilege and then shuts down the system.

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    /* Get a token for this process. */

    if (!OpenProcessToken(GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    error("OpenProcessToken");

    /* Get the LUID for the shutdown privilege. */

    LookupPrivilegeValue(NULL, TEXT("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)
    error("AdjustTokenPrivileges");

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

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

  8. #8
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    This is quoted from the Win32 API in Borland C++ 4.52 IDE.
    The price of using old help files is that they never tell you that the code you quote is for Windows NT/2000/XP only (given that Windows 9x has no security).

    ExitWindowsEx alone will work in Windows 9x from a GUI application. There is no function call to shut down Windows from a console application.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    >>There is no function call to shut down Windows from a console application.

    There is a possible cheat. I used to use the following as part of a close-down bat file for win 98

    rundll32 shell32.dll,SHExitWindowsEx 1
    ....at least I think thats it. If I get home and find its wrong I'll change it....

    Anyway I suppose you could use this as a system call......sloppy - but it might work....

  10. #10
    Unregistered
    Guest
    Anyone know where i can find tuturial for borland c++ builder 5?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 01:05 AM
  3. how do you make a program send data to the printer?
    By Sintu in forum C++ Programming
    Replies: 19
    Last Post: 10-20-2005, 07:22 PM
  4. startup program deleting shutdown? Need help
    By Miestese in forum Linux Programming
    Replies: 2
    Last Post: 07-06-2005, 09:05 PM
  5. shutdown program in c++
    By alanair23 in forum C++ Programming
    Replies: 5
    Last Post: 08-26-2001, 09:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21