aspose file tools*
The moose likes Java in General and the fly likes Shutting down the system after specified time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Shutting down the system after specified time" Watch "Shutting down the system after specified time" New topic
Author

Shutting down the system after specified time

sampath surineni
Greenhorn

Joined: Apr 02, 2012
Posts: 29

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

Joined: May 03, 2008
Posts: 4544
    
    5

Nothing to do with Swing / AWT / SWT / JFace. Moving to Beginning Java.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4544
    
    5

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

Joined: Feb 07, 2012
Posts: 344

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

Joined: Oct 13, 2005
Posts: 38851
    
  23
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

Joined: Oct 02, 2003
Posts: 11314
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sampath surineni
Greenhorn

Joined: Apr 02, 2012
Posts: 29

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

Joined: Feb 07, 2012
Posts: 344

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

Joined: Apr 02, 2012
Posts: 29

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

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Aug 22, 2008
Posts: 191

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.


Do not wait to strike till the iron is hot; but make it hot by striking....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Windows' shutdown.exe uses / for its flags. A shutdown after 25 seconds would be shutdown /s /t 25.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 22, 2008
Posts: 191

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

Joined: Sep 18, 2000
Posts: 562
    
    7

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

Joined: Apr 02, 2012
Posts: 29

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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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

Joined: Feb 07, 2012
Posts: 344

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

Joined: Oct 27, 2005
Posts: 19696
    
  20

Not anymore, I just tried.
shutdown does support - however (again, just tried it), but I dislike using anything that's not documented.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shutting down the system after specified time