Pc shutdown win XP / win98se

hi.all();

I try to shut down the computer with

Runtime.getRuntime().exec(“shutdown -s -f -t 20”);

which works fine with WIN XP - BUT: not with WIN98SE.

Any idea ??

many Thanks !

christian

Hi Christian,

I believe that Windows 98 SE does not have the command shutdown.exe . It is freely available on the internet somewhere (just google for it) however, I am not sure if it works for Win98 SE.

Martyn

Hi Martyn,

it took a little bit but I found :

http://users.pandora.be/jbosman/pwroff30.zip

NOT TESTED YET - but readme file looks ok.

Thanks very much for your help…

Christian

hi sync,
as martyn says best would be to create a *.jar-file and e.g. simply create a new link to it.
as you say you re new to java perhaps the short description of “How To Jar” will help. (don t care about the german filenames :wink:
best
christian

Real fast response :slight_smile:

Thanks!

You’ll need a try/catch block to catch an IOException. Like such:

import java.io.*;

public class foo
{
public static void main(String[] args) // i seen a few using String args[]
//i wonder which is the correct style
{
try {
Runtime.getRuntime().exec(“outlook”);
}
catch(IOException e) {
System.err.println(e);
}

}
}

Also, I just realised, that you’ll need to specify the full path of outlook.

By the way, String[] args or String args[] are both the same - both String arrays.

Martyn

Hi Martyn,

First, thanks for your respond.

public class foo
{
public static void main(String[] args) // i seen a few using String args[]
//i wonder which is the correct style
{
Runtime.getRuntime().exec(“outlook”);
}
}

javac foo.java
java foo

doesn’t compile :frowning:

Hi sync,

There is software to make a java application to executable (.EXE’s) but this software isn’t free. Anyway, why would you want to? Making your java application .EXE would make it platform specific (for windows). I think the best solution is creating a batch file which you can double click which runs your java application.

Alternatively, a little more complicated (but neater for larger projects) would be to create a Jar file. In the manifest indicate the main class you want to run. If you’ve done it correctly, you can double click on the jar file to run it.

The code for shutdown is nothing special. It uses java to call a windows application - namely “shutdown.exe”. The code for that is:

Runtime.getRuntime().exec(“shutdown -s -f -t 20”);

You must pass a String into the .exec() method which is the command string (in this case it’s “shutdown -s -f -t 20”). You could get it to open outlook by passing “outlook”.

I hope this answers your questions.

Martyn

Hi,

i’m new to java. Is it possible to make an exe file? like just click on it. It will be great if you can let me have a look on the codes how the shutdown thing work so i can make a modify it and make simple java program to start some of my daily program like email client, browser etc with simply one click to the java file.

Thanks,
sync

Hi Martyn.

Thanks for the help. The code worked perfectly. I have one last question is their a way to make the pc restart, hibernate or stand by?

thanks once again,
-Junior

Hi Zogan,

Add the following code to your actionPerformed() method.

=====

try {
Runtime.getRuntime().exec(“shutdown -s -f -t 20”);
}
catch(IOException e) {
System.err.println(e);
}

=====

Note that this will only work with computers which actually have “shutdown.exe” on their machines (2000/XP OS’).

Hope this helps.

Martyn.

Hi Guys,
I’m fairly new to Java programming. At the moment im trying to create a GUI with a shutdown button. I have created the GUI but I

Zogan,

I’m not sure how to do a hibernate, but to reboot the machine you will have to add a “/R” into the command string.

There are many other switches which you can use for the shutdown.exe program. To see them, in a DOS prompt, type “shutdown /?”.

Hope this was helpful.

Martyn

Hi martyn,
I`m naani. U have given the code like

(“shutdown -s -f -t 20”)

can U explain those parameters -s -f -t also what does 20 mean here.

Can we make a timed shutdown.
Thanks and cheers,
naani.

Hi naani,

ooops - i not absolutely sure anymore (would have to check again) :

-s : stops server
-f : closes frame
-t : total shutdown

but feel free to check here, if you have a little bit of time. http://forum.java.sun.com

“20” means the number of seconds until shutdown; so if e.g. you need a shutdown in one hour write “…3600”.

Please note that after RETURN the ONLY way to stop Shutdown again is

Runtime.getRuntime().exec(“shutdown -a”);

with a = abort.
Nothing else will stop the process :wink:
best, christian

can I get source code java to shutdown windows XP with timer

Hi abdhe,

If you read the posts above, the code has already been supplied. Here it is again:

======
try {
Runtime.getRuntime().exec(“shutdown -s -f -t 20”);
}
catch (IOException e) {
System.err.println(e);
}

======

Hope this helps.

Martyn

hi i have a friend who likes hacking into my computer and deleting stuff id like to return the favour and ideas how???

shutdown in windows2000karl page wrote:

hi i have a friend who likes hacking into my computer and
deleting stuff id like to return the favour and ideas
how???

when i run this code i always get this exception:

Java.IOException CreateProcess : shutdown -s -f -t 20

what should i do???