Is it possible to write a Java program to turn off the computer

Is it possible to write a Java program to turn off the computer

import java.io.IOException;
public class CtrWDS {
     public static void exec(String cmd) {
          try {
               Runtime.getRuntime().exec(cmd);
        catch (IOException e) {
            System.out.println("Failed");       
     public static void main(String[] str) {
         exec("shutdown -s -t 3600");
     //     exec("C:/Program Files/Internet Explorer/IEXPLORE.EXE");
     //     exec("regedit");
}

Similar Messages

  • How can i turn off the computer remotely using java?

    is it possible to use a java code for turning off the computer remotely by other computer in LAN?
    or if it is not possible how can i achieved that goal?
    thanx

    bd0 wrote:
    Well, if you're running linux you could use Runtime.getRuntime().exec() to execute 'halt -p', if the process was being run as root. Not terribly elegant but I suppose it would work. Although I wouldn't want an unattended process running as root.Yes, this is how you can do it, but on Windows machines as well. I'll go into pseudocode:
    App1: Server (running on every lab machine)
    open server socket on port X
    wait for connection
    verify connection is yourself so that not everyone can shut it down
    if not, wait for connection again
    if it is, run halt for linux or shutdown for windowsApp2: Client (running on just your computer)
    open a socket to each machine running the server app (or you could use multicasting)
    validate yourself however you did that
    close socketThere are some implications of this though - unless your validation mechanism is decent, pretty much anyone can shut down anything they want. Also, if you don't check for a logged-in user, you may destroy someone's work. Just keep those in mind.
    Also, if it is a Windows setting, there are usually better ways to do this - a well-managed windows network has built-in functionality to shut down computers remotely.
    Edited by: sprizor on Jun 22, 2008 10:59 AM

  • Is it possible to create a java program which can find the answer to any sudoku

    This is may sound as a beginner question but thats because i am a beginner. i have just learned the java language and now i am reading essential classes on oracle tutorials.
    anyway is this possible ? i think it is and i have been trying to do it but havent been sucessful. and if it is possible is it supposed to be easy ?
    i have been trying to do it by making a 2d array of 8 arrays having 8 ints each which is basically a sudoku. and creating a 1d array called possiblity having nos from 1 to 9. then using decision making statements and loops to eliminate the possiblities of each box and repeating until the sudoku is complete
    also if you could provide some project ideas that would be really appreciated.
    (PS i am still an intermediate at best so please dont provide very difficult project ideas)

    f1b8d129-b881-44f7-a736-5eef31471720 wrote:
    This is may sound as a beginner question but thats because i am a beginner. i have just learned the java language and now i am reading essential classes on oracle tutorials.
    anyway is this possible ?
    Yes.
    i think it is and i have been trying to do it but havent been sucessful. and if it is possible is it supposed to be easy ?
    Maybe.
    It should be easy to do a "brute force attack" to find the solution meaning that you simply try each and every possibility.
    i have been trying to do it by making a 2d array of 8 arrays having 8 ints each which is basically a sudoku. and creating a 1d array called possiblity having nos from 1 to 9. then using decision making statements and loops to eliminate the possiblities of each box and repeating until the sudoku is complete
    shouldn't there be 9 sqares with 9 fields each?
    also if you could provide some project ideas that would be really appreciated.
    But an array of primitives (int?) will not do the trick. Somehow you have to remember wich positions are fixed. and which numbers are still availabe for the current sqare.
    At your level the most obvisual approach may be a second array holding this information.
    I'd prefer to build a cusom object representing a square and another custom object to represent a field within this square with two attributes: currentNumber and isFix.
    Based on this the Sqare object could have a method to create a new combination by shifting the numbers that are not fix.
    If you need further assistance please show the code you have and what problem(s) you have with it.
    bye
    TPD

  • The program will not close properly unless I turn off the computer.

    The program will not close properly. If I close it and then try to restart it I get a message saying that Firefox is already running.

    Even under normal circumstances it takes a few seconds after exiting Firefox before you can launch Firefox again successfully.
    But you're right, sometimes a zombie Firefox process lives on, consuming CPU cycles and memory long after all the user interface for it has disappeared. The zombie Firefox process blocks the launch of new ones. It's annoying, but there is a lighter-weight work-around than rebooting. If you key Del while holding down Ctrl and Alt (the old three-finger DOS reboot), either the Windows Task manager will pop up immediately or you can select it from a list of options. In the Windows Task Manager's Processes tab, you should be able to find "firefox.exe" in the Image Name column. (Left-clicking the Image Name column will sort the names alphabetically, and then you can scroll up or down looking for "f".) Left-click on that "firefox.exe" and then left-click the "End Process" box. A warning box should then pop up, asking if you're really sure you want to terminate the process. Answer Yes. Then wait a few seconds for disk activity to die down. Then re-launch Firefox as you would normally.

  • Can I write a Java Program in Narrative view and make it work?

    Hi All,
    I got a requirement which demands me to write a java program in narrative view. As per my knowledge its not possible..........but do you guys have any work around or any other way to get that java program run when the report runs and the out must be seen on the dashboard???
    Thanks in advance,
    DK

    Joe thanks for the reply. I would like to communicate with a JavaScript API (MapQuest) by declaring a Proxy server and port number to communicate. Or I can directly use Java SDK to display maps.
    This is more a general question. If I can execute a java program then I will try doing many things.
    Thanks,
    DK

  • Is it possible to run a java program without using the command prompt?

    Hi,
    I was wondering whether it is possible to run a Java program (not an applet) without using a command line in the command prompt?
    Basically I want to run a program that will be continually running in the background and hence I don't want to have a command prompt screen loaded up as well - I just want the program to be running in the task bar.
    I know how to run the program in the task bar - but I still need to launch the program from the command prompt - is there anyway I can get a program running without having to start it from the command prompt?
    Cheers

    Or create a desktop shortcut (in Windows) or an application launcher ( in Linux GUI).

  • I want to write a java program that can add a user to a role or sub role to the Profile Database in iPlanet Portal Server 3.0. Does anyone has any idea or a sample program do such thing. Thanks, Tommy

    I want to write a java program that can add a user to a role or sub role to the Profile Database in iPlanet Portal Server 3.0. Does anyone has any idea or a sample program do such thing? Thanks, Tommy

    // create the user profile, get the handle back,
    // and set the membership profile attributes.
    ProfileAdmin newProfile = null;
    try {
    // the users profile name is the domain      
    // he belongs to plus their userName
    // you will request.domain if your doing this from a servlet, domain_name is the domain_name the user belongs too
    String profileName = domain_name + "/" + user;
         if (debug.messageEnabled()) {
    debug.message("creating profile for " + profileName);
    // create the user profile object
    newProfile = ProfileManager.createProfile(
    getSession(), profileName ,Profile.USER);
    UserProfile userProfile = (UserProfile)newProfile;
         // set the role the user is a member of. Default is to set
         // the users to the default role of the domain they surfed to
         StringBuffer roleName = new StringBuffer(64);
    // request.domain instead of domain_name if your doing this from a servlet ..
    Profile dp = getDomainProfile(domain_name);
    roleName.append(dp.getAttributeString("iwtAuth-defaultRole"));
         if (debug.messageEnabled()) {
    debug.message("setting role for " + user + " = " + roleName);
    userProfile.setRole(roleName.toString());
    newProfile.store(false);
    } catch (ProfileException pe) {
         debug.error("profile exception occured: ",pe);
    return;
    } catch (ProfileException pe) {
         debug.error("login exception occured: ",le);
    return;
    HTH ..

  • Can a java program be run in the background?

    Hi all,
    Can a java program be run in the background without the user being aware of it? I need to make a program that continuosly monitors a pc at regular intervals and runs at all time. It should be hidden(shouldn't display on the screen while running) from the user, and also, can it be run as a system file so that even if a user checks he/she would think of it as a system file?

    I'm the administrator of all the computers. Then as I said there are commercial applications that do that.
    Presumably you expect a problem now. And implementing an acceptable solution is going to take you months. Because not only need to 'hide' the application, you also need to set up all the monitoring and logging capability. And the first will require quite a bit of JNI work along with testing (in particular as it could interfer with existing applications on the users computers.)
    I need to
    install the software in all the machines and i want
    that the users who use the machine should not be able
    to close the program through the task manager. If the users have admin rights then they can terminate a windows service.
    And if they don't have admin rights then you can simply turn off the ability to install anything.
    I want
    to know what the resources of the computers are and
    that if anyone has added a resource to it or
    not(attaching a flash usb thumbdrive etc). Lots of JNI.

  • Is it possible to turn off the Apple dock completely?

    I was wondering if it was possible to turn off the Apple dock completely without causing irreparable damage to my system. I am considering using Drag Thing, but when I am using it the functionality seems redundant with the Apple dock, also using both programs in tandem uses up more precious memory. The Drag Thing website links to the following tutorial as a solution:
    http://www.creativemac.com/2003/02_feb/tutorials/dockdead2030225.htm
    But it was published a long time ago, and I don't want to do anything rash that would damage my system, I mean I don't dislike the Apple dock enough to do that. Thanks in advance for the consideration and suggestions.

    I could only discover an option to hide the dock from within Drag Thing. I am looking to make the dock disappear completely. Drag Thing does not officially support this option, giving this answer in the Q & A section of their website:
    "*It is possible, but I wouldn't recommend it. Since people often ask how to do it anyway, here's a good tutorial I found on how to kill the Dock by Kevin Schmitt. This may have unforseen side effects however, which is why I've not documented the procedure myself, or added an option for this in DragThing. I keep the Dock hidden off the bottom of the screen on my own Mac.*"
    Is the dock so embedded within the Finder's operations that killing it will affect system performance?

  • Turning off the annoying green rectangle around Java windows

    How does one turn off the annoying flashing green rectangle around Java windows? And how do you stop it from jumping to the top of other windows.
    Both of these functions are quite annoying and seem rather pointless.
    (I am using Firefox)
    Thanks

    Are you referring to some Applet that you have programmed or something you found on the net? Even for the latter case, I don't have either of the problems you mention, so it's probably related to the site or your browser settings.
    Please note that these forums are for support to developers and students of Java, not for every java product ever released.
    db

  • Is there a way to turn off the function in Lion that re-opens the last project you worked on in a given program?

    Is there a way to turn off the function in Lion that re-opens the last project you worked on in a given program?

    Dealing With The Resume Feature of Lion
    Managing Mac OS X Lion's application resume feature.
    If you shutdown your computer you should get a dialog asking if you want applications to resume on the next startup. Simply uncheck the box to prevent that from occurring. Open General preferences and uncheck the option to Restore windows when quitting and re-opening apps. You can also install a third-party utility to control resume features on individual applications: RestoreMeNot or Application State Cleaner.
    It is possible to completely stop the Resume feature although I'm unconvinced that it is that annoying. Nevertheless see the following:
    If you have not yet done so you must first make your /Home/Library/ folder visible. Open the Terminal application in the Utilities folder. At the prompt paste the following command line:
    chflags nohidden ~/Library
    Press RETURN. Quit the Terminal application.
    In the Finder navigate to the /Home/Library/Saved Application State/ folder. Delete the contents of the folder. Back up to the /Home/Library/ folder. Select the Saved Application State folder. Press COMMAND-I to open the Get Info window. In the Sharing and Permissions panel at the bottom click on the lock icon and authenticate. Set each of the listed entries to Read Only. Close the Get Info window.
    Quit all open programs except the Finder (this is very important.) Next, navigate to the /Home/Library/Preferences/ByHost/ folder. Look for a .plist file with "com.apple.loginwindow." in the file name followed by some numbers in hexadecimal. Select the file. Press COMMAND-I to open the Get Info window and in the Sharing and Permissions panel click on the lock icon and authenticate. Set each of the listed entries to Read Only. Close the Get Info window. If you also find a file with the same filename but with a last extension of ".lockfile," then you should delete it.
    The above should eliminate the Resume feature system-wide. Note that any future system updates or upgrades will likely undo these changes. You will then need to repeat this procedure assuming there are no major changes in OS X related to it.

  • How do i stop my programs from automatically popping up when i turn on the computer?

    how do i stop my programs from automatically popping up when i turn on the computer?

    When you log out or shut down, there will be a checkbox that asks you if you want to reopen windows when you log in. Just uncheck this box. If that isn't it, you may have login items turned on. Go to System Preferences>Users and Groups and then under your name click the Login Itens tab. Make sure nothing is there.
    If you want to stop windows from restoring when you open applications (so for example when you open Safari it doesn't open the 50 tab page you just had open when you quit) go to SystemPreferences>General and then hit the checkbox that says Close windows when quitting an application.

  • Please a simple problem but I don't know how to solve it. After installing 16 gb of ram all is good but when I turn on the computer it is a window signaling that all is correct. How is possible to delete once and for all that window? Thank you

    Please a simple problem but I don't know how to solve it. After installing 16 gb of ram all is good but when I turn on the computer it is a window signaling that all is correct. How is possible to delete once and for all that window? Thank you

    Well then maybe you could take a screenshot because the appearance of such a window is news to me.
    Also post your OS X version and what model Mac you have. The more detail, the better. Thanks.
    To take a screenshot hold ⌘ Shift 4 to create a selection crosshair. Click and hold while you drag the crosshair over the area you wish to capture and then release the mouse or trackpad. You will hear a "camera shutter" sound. This will deposit a screenshot on your Desktop.
    If you can't find it on your Desktop look in your Documents or Downloads folder.
    When you post your response, click the "camera" icon above the text field:
    This will display a dialog box which enables you to choose the screenshot file (remember it's on your Desktop) and click the Insert Image button.
    ⌘ Shift 4 and then pressing the space bar captures the frontmost window.
    ⌘ Shift 3 captures the entire screen.
    Drag the screenshot to the Trash after you post your reply.

  • I get a message that itunes  has stopped working. When I check out why it is because of the dep security on my computer. When I try to find the program for itunes for the .exe file i cannot find it to turn off the dep for  that file

    I get a message that itunes  has stopped working. When I check out why it is because of the dep security on my computer. When I try to find the program for itunes for the .exe file i cannot find it to turn off the dep for  that file

    I found the file but when I added it to the  list for the Data  Execution Program to ignore , I received a message that the Program.x86/itunes file must have the DEP on in order to run. Anyone else having this problem ?

  • Turning Off The Alert - Notebook PC Battery Replacement Program Alert in Health Check.

    I want to turn off the Notebook PC Battery Replacement Program Alert in Health Check. It continues to alert me for months now. This is driving me batty since I have checked it 3 times and it is not included in the recall! I have a HP Pavillion dv6000 running Windows Vista Home Premium Edition. Any help to turn this darn alert off permanently would be very helpful. Thanks.

    Thank you to all who have read this post so far.  Please continue to contact HP directly using the above information.
    Matthew|Community Advocate | Best Buy® Corporate
    Visit our Channel on
     Private Message

Maybe you are looking for

  • Why can't see my, or other people's pictures on myspace?

    When I sign in myspace. My profile pictores don't come up, or my friend's pictures either. Now when I called my friends, they CAN see my profile pictures, and other people's also. Can someone pleas help me? I tried contacting Verizon, but they couldn

  • WRT54G as a wireless AP

    I want to use one of the above as a wireless access point ( ie disble DHCP server and give it (or let it pick up) an IP address from a different server . I cant find a HowTo ( particularly to disable DHCP). I also want to run another machine with SQU

  • Regarding  XL Reporter

    Hi All,     I am facing the following error while trying to open the Report Definition in the Xl Report      <b> "Security settings in Microsoft Excel prohibit XL Reporter from running."</b>    Can anyone help me to solve this problem. Thanks & Regar

  • UML TOOL FOR CLASS DIAGRAMS??

    Hi, Can anyone tell me if there is an free tool which can draw the class diagrams if i give the root of my source directory or some package? Thanks

  • Case statement doubt

    Hi, I need some help with a simple case statement. lets say i have a table called name which has following 2 rows - ID first_name last_name 1 JOHN SMITH 2 JOHN i want to write a statement like :- select id,case when first_name like '%JO%' then 'John