用JAVA写了一个程序,怎么捕获系统要关机的命令
并在关机前提示用户一些信息

解决方案 »

  1.   

    用JNI调用C++来实现,C++来捕获系统要关机的命令是比较容易的。
      

  2.   

    出自:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4796976Bug ID:  4796976  
    Votes  9  
    Synopsis  RFE: Users cannot veto shutdown process in Windows  
    Category  java:classes_awt  
    Reported Against  1.4.1  
    Release Fixed   
    State  In progress, request for enhancement  
    Related Bugs   
    Submit Date  20-DEC-2002  
    Description  FULL PRODUCT VERSION :
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
    Java Hotspot(TM) Client VM (build 1.4.1_01-b01, mixed mode)FULL OPERATING SYSTEM VERSION :
    Microsoft Windows XP [Version 5.1.2600]A DESCRIPTION OF THE PROBLEM :
    Applications running under Windows receive the
    WM_QUERYENDSESSION message when a user wants to logoff or
    shutdown Windows.  Applications can veto the shutdown by
    returning FALSE to this message.In response to this message, most desktop applications
    show a dialog to the user for dirty documents allowing
    users to save their work or cancel the shutdown.
    ……----------------------------------------
    呵呵,早就有人抗议了,但是“In progress, request for enhancement”,等吧。
      

  3.   

    另外,我认为在java中使用jni也无法做到捕捉系统关机消息。
      

  4.   

    JAVA做不到这样的底层,这是JAVA的优势造成的缺陷,没有办法。要么JNI,要么等待。