Hi all. I want to be able to shutdown remote computers using Java.
Below are the things that have been imported :
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.*;
import java.rmi.server.*;
import javax.swing.*;
and below is the code
public void remoteShutdown_actionPerformed(ActionEvent e) {
try{
Runtime.getRuntime().exec("shutdown -m \\toshiba_cwb -s -t
99");
}catch(Exception ex){System.out.println("Fail to
ShutDown"+ex);}
The code works fine without the the -m and the computer name, however
when I put the -m \\computerName it won't shut the computer down but
no error messages have been displayed.
What is wrong with this.
Any help in this matter would be truly appreciated.
christopher_board@yahoo.co.uk wrote On 06/14/07 17:08,:
> Hi all. I want to be able to shutdown remote computers using Java.
> Below are the things that have been imported :
[quoted text clipped - 21 lines]
>
> Any help in this matter would be truly appreciated.
I have no idea what this "shutdown" program you're
using is; it certainly doesn't look like the one I know.
Nonetheless, I have a suspicion: are the two backslashes
part of the actual command syntax? That is, do you need
two backslashes in the executed command line? If so, be
aware that what you've written is only *one* backslash,
because of the way the Java compiler uses \ in strings
to introduce hard-to-type characters. To get two, you'll
need to double up each of them:
... ("shutdown -m \\\\toshiba_cwb ...");
Depending on what happens to the command line after
you launch it, even that might not be enough. For example,
if the \ is also special to the command processor ("shell"),
then you may need to double it yet again or escape it by
whatever mechanism the shell uses:
... ("shutdown -m \\\\\\\\toshiba_cwb ...");
(Intepretation: The Java compiler generates one "delivered"
backslash for each pair in the source, making four. Then
the shell makes one backslash out of each pair that *it*
sees, making two. YMMV.)

Signature
Eric.Sosman@sun.com
christopher_board@yahoo.co.uk - 14 Jun 2007 23:35 GMT
> christopher_bo...@yahoo.co.uk wrote On 06/14/07 17:08,:
>
[quoted text clipped - 53 lines]
>
> - Show quoted text -
Thanks for your help that works fine
Brandon McCombs - 16 Jun 2007 05:20 GMT
> christopher_board@yahoo.co.uk wrote On 06/14/07 17:08,:
>> Hi all. I want to be able to shutdown remote computers using Java.
[quoted text clipped - 25 lines]
> I have no idea what this "shutdown" program you're
> using is; it certainly doesn't look like the one I know.
It's the CLI way of shutting down a Windows PC. The OP took it for
granted that wanting to shutdown remote computers really meant to us
that he wanted to shutdown only Windows-based remote computers since
Windows-based computers are the only ones that exist.
> Runtime.getRuntime().exec("shutdown -m \\toshiba_cwb -s -t
>99");
to solve a problem like this, first solve it issuing the shutdown
command from the command line.
Then when you have that working, use quoter at
http://mindprod.com/applets/quoter.html
to convert the command line into a java string that you can feed to
exec. It handles the \ doubling etc. for you.
See: http://mindprod.com/jgloss/shutdown.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com