Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Remote Shutdown using Java

Thread view: 
christopher_board@yahoo.co.uk - 14 Jun 2007 22:08 GMT
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.
Eric Sosman - 14 Jun 2007 22:29 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.
> 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.
Roedy Green - 15 Jun 2007 10:36 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.