Which method is better?

This is a discussion on Which method is better? within the Windows Programming forums, part of the Platform Specific Boards category; system("shutdown -s -t 10"); vs ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER); Which is better? and why?...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    38

    Which method is better?

    system("shutdown -s -t 10");
    vs
    ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER);



    Which is better? and why?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    The later, obviously. It's more secure, and it's faster.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    Wow.. an user application can shut down Windows just like that ?....no complains from the operating system or other users that might be logged in ?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    Of course they can, with proper permissions, of course.
    They have to request permission to be able to shut down the system first. If that requires admin privileges or not, I don't know.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    @manasij7479 I'm not sure, but i'll assume SHTDN_REASON_MAJOR_OTHER will give some kind of message, because system(); give a message. Although i haven't tired it yet so i wouldn't know.

    I'm having trouble running exitwindowsEx. It seems more complicated than system();. Could someone figure out what is wrong with the code below? I can't seem to complie the error();.


    Code:
    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,   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_REBOOT  |   EWX_FORCE,   0))

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    Quote Originally Posted by airesore View Post
    @manasij7479 I'm not sure, but i'll assume SHTDN_REASON_MAJOR_OTHER will give some kind of message, because system(); give a message. Although i haven't tired it yet so i wouldn't know.
    No, it won't. This is an API; not an application. APIs typically don't display messages. That is the application's job.
    shutdown is an application, while ExitWindowsEx is not.

    You should post your query in the Windows forum.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    Moved
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by manasij7479 View Post
    Wow.. an user application can shut down Windows just like that ?....no complains from the operating system or other users that might be logged in ?
    "Shutdown", "halt", "reboot", etc, are user applications. On *nix systems this is done via kill(1,...).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    ok nvm, i figured it out. Cheers

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    Share your solution with the rest of the world, that others may benefit from this topic and your problem!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. difference between this->method() and method()
    By nacho4d in forum C++ Programming
    Replies: 7
    Last Post: 11-21-2009, 03:11 PM
  2. Encrypt method (from decrypt method)
    By mmmmmm in forum C# Programming
    Replies: 3
    Last Post: 09-19-2009, 10:35 AM
  3. calling a class method within different class method
    By alyeska in forum C++ Programming
    Replies: 5
    Last Post: 03-08-2009, 10:56 AM
  4. need help with a method
    By laasunde in forum C++ Programming
    Replies: 17
    Last Post: 10-28-2002, 11:08 AM
  5. Have a better method of doing this?
    By Golden Bunny in forum C++ Programming
    Replies: 4
    Last Post: 06-25-2002, 11:49 AM

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