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 / First Aid / August 2007

Tip: Looking for answers? Try searching our database.

Shutdown computer with message

Thread view: 
christopher_board@yahoo.co.uk - 30 Aug 2007 22:30 GMT
Hi all. I am currently developing a java program that will shutdown
computers which are connected to a network. I have a function that is
able to shutdpwn the computer with a shutdown message by passing code
to the command prompt. The shutdown type that I am using for the
command prompt would be
shutdown -m \\computername -r -c "shutdown message" -f.

The -c set what the shutdown message is going to be.

If I run the program and in the box type Hello it works fine and
shutsdown the computer, however if I type Hello World it stops the
program from being able to be shutdown, however if I put HelloWorld
the programs works fine again and shuts the computer down showing the
message. It doesn't seem to like a shutdown message with spaces in.

The code that I am using to perform this shutdown is below:

try {
     Runtime.getRuntime().exec("shutdown -m \\\\"+
remoteshutdown.mainScreen.lstComputerNames.getSelectedValue()+ "
-r -t 30 -f -c " remoteshutdown.mainScreen.txtShutdownMsg.getText());
} catch (Exception ex) {
System.out.println("Fail to ShutDown" + ex.toString());
}

Any help in this matter would be highly appreciated.

Thank you
Real Gagnon - 30 Aug 2007 22:42 GMT
christopher_board@yahoo.co.uk wrote in news:1188509418.398860.228520
@q4g2000prc.googlegroups.com:

> It doesn't seem to like a shutdown message with spaces in.

Try to put each element of your command line in an array.

Something like

String[] cmd = { "myProgram.exe", "-o=This is an option" };
Runtime.getRuntime().exec(cmd);

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html

Thomas Fritsch - 31 Aug 2007 00:31 GMT
>       Runtime.getRuntime().exec("shutdown -m \\\\"+
> remoteshutdown.mainScreen.lstComputerNames.getSelectedValue()+ "
>  -r -t 30 -f -c " remoteshutdown.mainScreen.txtShutdownMsg.getText());
It is usually more reliable to command-splitting by yourself, instead of
 letting Runtime#exec do the command-splitting. Try this:

String[] cmdArray = {
  "shutdown",
  "-m",
  "\\\\" + remoteshutdown.mainScreen.lstComputerNames.getSelectedValue()
  "-r",
  "-t",
  "30",
  "-f",
  "-c",
  remoteshutdown.mainScreen.txtShutdownMsg.getText()
};
Runtime.getRuntime().exec(cmdArray);

Signature

Thomas

Roedy Green - 31 Aug 2007 05:08 GMT
>shutdown -m \\computername -r -c "shutdown message" -f.

see http://mindprod.com/jgloss/shutdown.html
Signature

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



©2010 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.