• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to control native operating system operations with my java app

 
Greenhorn
Posts: 29
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to turn off my system by pressing a "Turn Off Computer" button in my java application. Can anyone help me in getting the code for that....?? I am using WINDOWS 7 HOME PREMIUM
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richards Milan wrote:I need to turn off my system by pressing a "Turn Off Computer" button in my java application. Can anyone help me in getting the code for that....?? I am using WINDOWS 7 HOME PREMIUM



Well, depending on what is installed, and your permissions, you may be able to do a system exec to the windows "shutdown" command.

Henry
 
Richards Milan
Greenhorn
Posts: 29
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well, depending on what is installed, and your permissions, you may be able to do a system exec to the windows "shutdown" command.

can you elaborate it .. because I want to create an application using java that checks the password and shuts the system down when the user types in the wrong password !
any help with the code>>
 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richards Milan wrote: Because I want to create an application using java that checks the password and shuts the system down when the user types in the wrong password !
any help with the code>>


No, you can't do this in pure Java , because the JVM itself gets started when user successfully logged-in , and in your case No JVM means No Java app can run as simple is that ...
 
Henry Wong
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richards Milan wrote:can you elaborate it .. because I want to create an application using java that checks the password and shuts the system down when the user types in the wrong password !
any help with the code>>




To elaborate ....

1. Take a look at the javadoc for the java.lang.Runtime and java.lang.Process classes.
2. Take a look at this article about using those classes -- http://www.javaworld.com/jw-12-2000/jw-1229-traps.html
3. Take a look at the windows command that you want to execute -- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/shutdown.mspx?mfr=true


Henry
 
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richards Milan wrote:I need to turn off my system by pressing a "Turn Off Computer" button in my java application. Can anyone help me in getting the code for that....?? I am using WINDOWS 7 HOME PREMIUM



Well you can try doing this by getting reference to the runtime object associated with your java application (use static method getRuntime() of Runtime class for the same) and then pass on the String array mentioning the shutdown command and the required arguments to the exec(String[] cmdarray) method of the Runtime class. I think it will work then.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankush Kaundal wrote:
Well you can try doing this by getting reference to the runtime object associated with your java application (use static method getRuntime() of Runtime class for the same) and then pass on the String array mentioning the shutdown command and the required arguments to the exec(String[] cmdarray) method of the Runtime class. I think it will work then.


He is not trying to close the windows after user successfully logged in ...actually he wants windows to shutdown when user enter wrong password at the log-in screen of windows

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richards Milan wrote:I need to turn off my system by pressing a "Turn Off Computer" button in my java application. Can anyone help me in getting the code for that....?? I am using WINDOWS 7 HOME PREMIUM


Personally: I wouldn't try. Java is not the OS; and furthermore it's supposed to be platform-independent.

If it was me, I'd have my Java app return a code (say 98 - good old COBOL return code) when it exits to indicate that the user requested a shutdown, and then have the script or .BAT that runs the app do the shutdown for me.

Winston
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richards Milan wrote:I need to turn off my system by pressing a "Turn Off Computer" button in my java application. Can anyone help me in getting the code for that....?? I am using WINDOWS 7 HOME PREMIUM


Ohh so you have "turn off button" in your Java app then offcourse this is possible write a shutdown script for windows use *.bat or in *nix systems use *.sh file which contains command to shutdown system and run that file using Runtime or ProcessBuilder class
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic