• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remotely checking Windows services in java

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi good Afternoon,
I am trying to check some particular windows services running or stop remotely throw java program that program works fine in local system and give the out put but when i put Ip address of remote machine that is not showing anything thing but in command prompt it display the output of remote computer not in java program, My java program is like that

package com.sadhu;

import java.sql.*;
import java.io.*;
import java.text.*;
public class CheckServices
{
public static void main(String args[])
{
try
{
Process p=Runtime.getRuntime().exec("sc query ALG");

BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));

String line=reader.readLine();
while(line!=null)
{
if(line.trim().startsWith("STATE"))

{

if (line.trim().substring(line.trim().indexOf(":")+1,line.trim().indexOf(":")+4).trim().equals("1"))
System.out.println("Stopped");
else
if (line.trim().substring(line.trim().indexOf(":")+1,line.trim().indexOf(":")+4).trim().equals("2"))
System.out.println("Startting....");
else
if (line.trim().substring(line.trim().indexOf(":")+1,line.trim().indexOf(":")+4).trim().equals("3"))
System.out.println("Stopping....");
else
if (line.trim().substring(line.trim().indexOf(":")+1,line.trim().indexOf(":")+4).trim().equals("4"))
System.out.println("Running");

}
line=reader.readLine();
}

}

catch(IOException e1) { }



}
}


It works fine for Local system but not working for remote server , i put command line "sc \\43.45.46.100 query ALG" it display the status of Remote Services ,When i put "sc \\43.45.46.100 query ALG" in place of "sc query ALG" then it is not working or not showing anything


Thanks in Advance
SCP

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you escape the \\ in your Java String to \\\\?
 
sadhu charan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob Spoor That is solved I did like this sc \\\\43.45.46.100 and it work fine , Thanks once again
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
sadhu charan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob Spoor It is working for Services which only contain one word like "ALG" but which window services contain space in middle like "SOS SIT Standby-38087" that is not working in this command like
sc \\\\43.45.46.100 query SOS SIT Standby-38087 or i did like sc \\\\?43.45.46.100 query SOS SIT Standby-38087 boths are not working can you help me ,
Thanks in advance
SCP
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving thread because it is too difficult for “beginning”.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote the service name. The command is sc \\43.45.46.100 query "SOS SIT Standby-38087" so as a String it becomes this (escaping the \ and " characters):
But are you sure that's the service name, and not just the display name?
 
sadhu charan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all it is working which is suggested by Rob Spoor

Thank you
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above code mentioned in the question is throwing the below error! Can any one help me out!

[SC] OpenSCManager FAILED 5:
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know myself, but welcome to the Ranch
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error code 5 means ERROR_ACCESS_DENIED. That means the user you are running the command as simply doesn't have enough rights to perform the operation.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"sc \\\\43.45.46.100 query ALG" is not working for me
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic