Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Restart network PCs by using Java  (Read 13337 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Restart network PCs by using Java
« on: November 15, 2019, 05:57:39 PM »
Dear All,

I Can restart my PC using Java but i want to give that command to any PC on my network as i have about 500 or more , so can any one help me in detailed way
I created a simple form with two text fields number one takes the number of seconds it will takes and the second one takes the host-name of any machine and at last the Button which execute the restart command and as i said it works properly with my PC without using the second text field but i don't know the right command to make it restart the network PC and can't convert my code to do that.
here is may code inside the Button below , so kindly if you can do that write my code again with the right way:


        Runtime runtime = Runtime.getRuntime();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      
        //System.out.print("Enter No. of Seconds after which You want your Computer to Shutdown :");
        String a;
        String h;
        try {
            a = txt1.getText();
            h = txt2.getText();
            long r = Integer.parseInt(a);
            Process proc = runtime.exec("shutdown -r -t"+r);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex);
        }
      
        System.exit(0);

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Restart network PCs by using Java
« Reply #1 on: November 16, 2019, 06:05:32 PM »
Abo-Zead,
What you want to do is too much like malware.
Yes, yu can power down  your own PC because you are the owner and administrator.  :D
Shooting down a remote machine invokes security rules.  8)

To shut down 500 PCs, you need permission to control each one. That kind of power is restricted for general use. In other words, you can not do if.  :-*

How to shut down your own PC with software is well documented. The documents never tell you how to shut down hundreds of PCs. If there is such a program, such a script must certainly malware and can not be reveled on this forum.  >:(
 
Noe, having said that, here is info from CH  archives:
How to remotely shutdown another Windows computer
Quote
Tip
You need administrative privileges to access and shut down the computer remotely to complete the following steps.
So there.

Please read the whole thing.  It is very accurate and update.

Can you explain why you are doing this?
« Last Edit: November 16, 2019, 06:17:05 PM by Geek-9pm »

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Restart network PCs by using Java
« Reply #2 on: November 16, 2019, 06:17:55 PM »
Geek-9pm
Thanks for your response but I already created a batch file to do what i want like remote registry change ,  restart one Or couple Or even all of them as i want with considering the restart time for each PC  and some simple command and have no restrictions in my company
but i want to do that with Java program instead of batch files , so can you help me.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Restart network PCs by using Java
« Reply #3 on: November 20, 2019, 09:29:29 PM »
I Found some people were talking about the use of the server and client and other people talked about the use of socket service and i wasn't know about its really and after i knew it  i didn't like it , so I thank Allah for guiding me to the truth of that issue and as i was wanted to give the order to my computer directly without any mediator like any service then the operating system and network protocols taking the responsibility for sending my command to other PC on my network then the other PC directly execute my command as it using the same operating system that exactly what i want
here is my last code below if it helping any one latter

String Time = "0";
                   Time = txt1.getText();
        String HostName = txt2.getText();
        String shutdownCmd = "shutdown -r -t "+Time+" -m \\\\"+HostName;
        try {
            Process p = Runtime.getRuntime().exec(shutdownCmd);
        } catch (IOException ex) {
            Logger.getLogger(frmRestart.class.getName()).log(Level.SEVERE, null, ex);
        }