Ok...I think this can be done in Java but I have no clue how. What I want is a small application for Windows XP that would make it so that if a user clicks shutdown (from the start menu or from the welcome page) it will as for the correct password (which would need to be able to be reset) and I could manage little things like that and it would be availble through the System Tray (next to the time). I have no clue where to start with this and don't know any of the coding...where should I start?

-Computerpros

Dani AI

Generated

Short answer: it’s doable on Windows, but not with “pure” Java alone on WinXP. The OS delivers shutdown events to native windows (WM_QUERYENDSESSION / WM_ENDSESSION) and the clean, supported places to hook those notifications are native code (a small native app with a message loop, or a Windows Service). ’s advice to use C++/Delphi is the pragmatic route, and was right that a plain Java-only app isn’t designed for that low-level integration. For a Java-based path, the realistic options are a JNI/JNA native bridge or the newer AWT/Desktop quit handlers on recent JDKs — there are community examples showing a JNA window that handles WM_QUERYENDSESSION. (stackoverflow.com)

How Windows delivers shutdown: when the system shuts down it sends WM_QUERYENDSESSION to top-level windows (an app can decline and cancel shutdown on XP), and services receive shutdown/preshutdown control codes. That is the documented mechanism, so any reliable “ask for a password on shutdown” implementation must receive those OS messages and block or delay shutdown while prompting. Note that later Windows releases (Vista+) changed shutdown UI/behaviour (forceful shutdowns, centralized blocking reasons), so behaviour differs across versions and a user/admin can still force shutdown or terminate a blocker. (learn.microsoft.com)

Practical options and a safe recommendation: for genuine access control, use Windows policy — remove the Shut Down command or restrict the “Shut down the system” right via Group Policy (this is the secure, supported approach). If an app-level prompt is required anyway, implement it as native code (or Java + JNA/JNI) that creates a hidden/top-level window and handles WM_QUERYENDSESSION, or run a Windows Service and handle SERVICE_CONTROL_SHUTDOWN/preshutdown. A quick command to abort a pending countdown is shutdown /a, but that only cancels an already-scheduled shutdown and doesn’t enforce restrictions. Prototype on an XP test VM and remember: any user with sufficient privileges (or physical access) can bypass process-level blockers. (learn.microsoft.com)

Relevant thread points: ’s goal is understandable; ’s note about shutdown -a is only partly relevant (it aborts pending shutdowns); ’s and ’s cautions about it being a Windows-level hack are on target.

Recommended Answers

All 9 Replies

You'd be better off writing that sort of thing in C++ or Delphi with maybe some Assembler code as well.

Member Avatar for Member #46692

>You'd be better off writing that sort of thing in C++ or Delphi with maybe some Assembler code as well.

Can you even use windows commands from java? Like shutdown,'n' stuff?

[edit]
Just found


I guess java is just accessing the commands for shut-down, which are platform specific anyway?

Sorry to hijack this thread with a different question altogether :-)
[/edit]

You could call shutdown-a, but it's not going to automatically restrict it for you.

So then...can this be coded in Java or not?? Let me know so that I can post in another board if nessesary.

-Computerpros

I am pretty sure you cannot. Trying to intercept the shutdown call,
seems to me, to be a pretty system-level function, and Java is not
intended, or designed, for that type of functionality.

Member Avatar for Member #46692

>What I want is a small application for Windows XP that would make it so that if a user clicks shutdown (from the start menu or from the welcome page) it will as for the correct password (which would need to be able to be reset)

This sounds more like a windows hack anyway.

Member Avatar for Member #46692

>What I want is a small application for Windows XP that would make it so that if a user clicks shutdown (from the start menu or from the welcome page) it will as for the correct password (which would need to be able to be reset)


This sounds more like a windows hack anyway.

So then...can this be coded in Java or not?? Let me know so that I can post in another board if nessesary.

-Computerpros

How about doing your own research?

Thanks guys...:rolleyes:

-Computerpros

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.