Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shutting down the system after specified time

 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends.

This is my first post here.

I am thinking of writing a program that would shutdown the system after the specified time.

Can anyone help me by telling the different ways to shutdown a system with java.
and different ways to count time so that it shuts down at the specified time.

Thank you in advance
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with Swing / AWT / SWT / JFace. Moving to Beginning Java.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sampath surineni wrote:I am thinking of writing a program that would shutdown the system after the specified time.

I'm curious. Why do you need this and why do you think Java would be a good choiice for implementing it?

And welcome to the Ranch!
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't directly do this from Java. Your java app would have to call either the shutdown.exe program (i.e. exec() method in Runtime.getRuntime()) or use JNI (Java Native Interface) to call the appropriate windows functions directly (this requires a lot more work, plus you would have to write a bit of code in C++ or other "low-level" language and call that from your Java app).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Nothing to do with Swing / AWT / SWT / JFace. Moving to Beginning Java.
Too difficult for “beginning“, so it will have to move again.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Koen Aerts wrote:Your java app would have to call either the shutdown.exe program (i.e. exec() method in Runtime.getRuntime()) or use JNI (Java Native Interface) to call the appropriate windows functions directly

Who said anything about it being a Windows system?
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
sampath surineni wrote:I am thinking of writing a program that would shutdown the system after the specified time.

I'm curious. Why do you need this and why do you think Java would be a good choiice for implementing it?

And welcome to the Ranch!


Actually there were situation when I am downloading something and want to shut down the system after that.Some times I cant wait for it to download and shut it down. SO I want to have an app for that. I want to do it with java because I want to be a java programmer.
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sampath surineni wrote:
Darryl Burke wrote:
sampath surineni wrote:I am thinking of writing a program that would shutdown the system after the specified time.

I'm curious. Why do you need this and why do you think Java would be a good choiice for implementing it?

And welcome to the Ranch!


Actually there were situation when I am downloading something and want to shut down the system after that.Some times I cant wait for it to download and shut it down. SO I want to have an app for that. I want to do it with java because I want to be a java programmer.

That's a bad reason. Java is simply not meant for such low-level functions. You have to use the languages/tools that are more applicable for the purpose. For instance for shutting down a system you either write a script or you use a language that provides direct access to the low-level OS functions, such as C++.
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Koen Aerts wrote:
sampath surineni wrote:
Darryl Burke wrote:
sampath surineni wrote:I am thinking of writing a program that would shutdown the system after the specified time.

I'm curious. Why do you need this and why do you think Java would be a good choiice for implementing it?

And welcome to the Ranch!


Actually there were situation when I am downloading something and want to shut down the system after that.Some times I cant wait for it to download and shut it down. SO I want to have an app for that. I want to do it with java because I want to be a java programmer.

That's a bad reason. Java is simply not meant for such low-level functions. You have to use the languages/tools that are more applicable for the purpose. For instance for shutting down a system you either write a script or you use a language that provides direct access to the low-level OS functions, such as C++.


Ok thank you for the advice.I just wanted to see if I can do it.I'll try as you said with c++
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A viable idea might be to let the user configure a command that would be run after all downloads finish. You'd then run that command from your program (still some work to do, but generally doable in Java). Your users might then have to battle the Windows' UAC control, which might interfere with the command, but that would be their problem, not yours And you'd keep platform independence of your application.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can create a batch file in Windows like
shutdown -t 25


here 25 is the time in seconds after which the system will be shutdown once this command get executed.
you can call this batch file in your java program to make the system shut down.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows' shutdown.exe uses / for its flags. A shutdown after 25 seconds would be shutdown /s /t 25.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for using JNI, I've done that and didn't like it one bit. It's not just calling one simple function (ExitWindowsEx), but also a few others to allow it to be used; AdjustTokenPrivileges being just one of them.
 
Paul Clapham
Sheriff
Posts: 21136
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sampath surineni wrote:I want to do it with java because I want to be a java programmer.


One attribute of a good Java programmer is that they know what to use Java for. And by this point you should have noticed that shutting down the system isn't one of those things. And not only that, most of the obstacles you have to surmount to get the thing working have nothing at all to do with Java so you wouldn't even learn much about Java by doing it.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Windows' shutdown.exe uses / for its flags. A shutdown after 25 seconds would be shutdown /s /t 25.

I always use it with hyphen(-)
like: shutdown -s
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also don't forget.... many people use their systems for multiple purposes..... there might be something more important to them then what you are doing..... if you don't give them a chance to say no (which means you will have them shutdown) they might just hunt you down and kick your a$$. (just a word to the wise).
 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sampath surineni wrote:Hi friends.

This is my first post here.

I am thinking of writing a program that would shutdown the system after the specified time.

Can anyone help me by telling the different ways to shutdown a system with java.
and different ways to count time so that it shuts down at the specified time.

Thank you in advance

thank you everyone for your help.I'm happy to get these many responses
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manoj Kumar Jain wrote:
Rob Spoor wrote:Windows' shutdown.exe uses / for its flags. A shutdown after 25 seconds would be shutdown /s /t 25.

I always use it with hyphen(-)
like: shutdown -s

If that works you either use a different shutdown (not the one provided by Windows itself)*, or you're using an undocumented feature. I would switch to using / as that's officially supported.

* shutdown -s is one of the ways to do it on Linux, so perhaps you're using a ported version of the Linux shutdown executable.
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Manoj Kumar Jain wrote:
Rob Spoor wrote:Windows' shutdown.exe uses / for its flags. A shutdown after 25 seconds would be shutdown /s /t 25.

I always use it with hyphen(-)
like: shutdown -s

If that works you either use a different shutdown (not the one provided by Windows itself)*, or you're using an undocumented feature. I would switch to using / as that's officially supported.

* shutdown -s is one of the ways to do it on Linux, so perhaps you're using a ported version of the Linux shutdown executable.

If I remember correctly from the old DOS-days, you can use either - or / to specify arguments. For instance "dir -?" or "dir /?"
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not anymore, I just tried.
shutdown does support - however (again, just tried it), but I dislike using anything that's not documented.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic