Remote Shutdown using Java

C

christopher_board

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.
 
E

Eric Sosman

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.

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.)
 
C

christopher_board

(e-mail address removed) wrote On 06/14/07 17:08,:











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.)

Thanks for your help that works fine
 
B

Brandon McCombs

Eric said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top