Start and Stop a Windows Service From Java
Is there any way to start and stop a Windows service from Java? The only post I found on it (http://forum.java.sun.com/thread.jspa?threadID=647509) had a link to one of the many aps that allow Java programs to be services, which is not what I am interested in doing.
I am attempting to get data from performance counters from the Windows Performance Monitor into a Java ap without using JNI. I can get the data from C++ or a .net language pretty easily and was going to create a service that would listen for socket requests and feed back the data. However, I'd like to start and stop that service when my java code starts and stops. Is this possible? Would it make more sense to just use a .exe and Runtime.exec()?
If it's only to start or stop a service then you could use the net command without any need for JNI.import java.io.*;
public class MsWinSvc {
static final String CMD_START = "cmd /c net start \"";
static final String CMD_STOP = "cmd /c net stop \"";
public static int startService(String serviceName) throws Exception {
return execCmd(CMD_START + serviceName + "\"");
public static int stopService(String serviceName) throws Exception {
return execCmd(CMD_STOP + serviceName + "\"");
static int execCmd(String cmdLine) throws Exception {
Process process = Runtime.getRuntime().exec(cmdLine);
StreamPumper outPumper = new StreamPumper(process.getInputStream(), System.out);
StreamPumper errPumper = new StreamPumper(process.getErrorStream(), System.err);
outPumper.start();
errPumper.start();
process.waitFor();
outPumper.join();
errPumper.join();
return process.exitValue();
static class StreamPumper extends Thread {
private InputStream is;
private PrintStream os;
public StreamPumper(InputStream is, PrintStream os) {
this.is = is;
this.os = os;
public void run() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null)
os.println(line);
catch (Exception e) {
e.printStackTrace();
}Regards
Similar Messages
-
Start and stop the Communication channel from Java Mapping
How to start and stop the Communication channel from Java Mapping in XI 3.0
Scenario PI - > MQ -> Third Party web application
Web application is down and then Communication channels are stop manually .
We need to automate this process,
MQ Solution - Trigger will be set in MQ which will be called when web application is stopped
Trigger will send u201CSTOP u201C message to PI
How to configure PI scenario to stop different com channels when this message received ?check this link: http://help.sap.com/saphelp_nw04/helpdata/EN/45/0c86aab4d14dece10000000a11466f/frameset.htm
make sure that MQ send http request to PI. i dont think a configuration scenario is required in PI. Only roles should be enabled with proper user provided to MQ team.
However, for security reasons, you can configure a scenario if you dont want to expose PI infrastructure directly to 3rd parties. -
How to start and stop the BI Services in Solaris 10
Hello All,
Can anyone guide me on how to start and stop the BI Services in Solaris 10. In windows there are options set in Start->Programs->Middleware_Home->Start/Stop BI Services.
Primarily after doing changes to the scheduler configuration, I need to restart the services to get it implemented? If yes how can I do it?
Any help will be appreciated
Thank you
Ash
Edited by: 902739 on Jan 11, 2012 12:17 PMPlease help me by showing action plan for stop sap , offline backup and then start sap.
i am little bit confuse How to start and stop SAP on cluster for offline backup
Below are the systems name with host name , please explain me in sequence
Systems name Hostname
# Hope SAP ERP Prod DB Primary gsgbbux860
# Hope SAP ERP Prod DB Standby gsgbbux861
# Hope SAP ERP Prod Cluster gsgbbux862
# Hope SAP ERP App 1 gsgbbux864
# Hope SAP ERP App 2 gsgbbux865
Thanks in advance
Zaheer -
Start and Stop Oracle BI services on UNIX box?
Hi All,
We have OBIEE installed on the Unix Servers and want to start and stop the Bi services.
What is the command to do so?user11001347 wrote:
Hi,
At the Unix prmompt I am executing the following command but it throws an error saying : run-sa.sh command not found,I am in the OracleBI\Set up Directory on the unix machine
-bash-3.00$run-sa.sh stop
does anyone has idea is that the exact command to I am missing anything?In what directory are you trying to execute that command? Do "pwd" to see where you are. You seem to need Unix training. In Unix (like in DOS) you can only execute a command/program that exists the PATH environment variable. Most likely the OBIEE bin directory won't be in the path, unless someone specifically added it. Further more the current directory (referred as ".") is not usually in the PATH variable either so when you execute commands you have to prefix them with the full path or with the current directory as Vinodh suggested. -
Allow a user access to start and stop a particular service in Solaris 11 using RBAC controls
So, using svcbundle I created a service called "oracle" that starts and shutdown a db. I'm aware of how to grant RBAC access to be a "service operator" to be able to control start/stop ALL services. But I'd like to grant a user access to start and stop JUST this service.
in this document on page 15, it states that it's possible to do this kind of granularity but doesn't explain how to do it step by step.
how does one achieve this?
thanks.You need to add a property group such as
<property_group name='general' type='framework'>
<!-- to start stop oracle -->
<propval name='action_authorization' type='astring'
value='solaris.smf.manage.oracle' />
</property_group>
Then add the solaris.smf.manage.oracle authorization to the user profile.
As an example, see Less known Solaris features: RBAC and Privileges - Part 2: Role based access control - c0t0d0s0.org -
Monitoring windows services from JavaI Know how to
I know how to start and stop services in java, but how can I see if a process is already stared or is starting?
ThxYou'll need to make a call to a suitable Windows program using Runtime or ProcessBuilder methods, or use JNI (Java Native Interface.) From Wikipedia:
(JNI) is a programming framework that allows Java code running in the Java virtual machine (JVM)
to call and be called[1] by native applications (programs specific to a hardware and operating system
platform) and libraries written in other languages, such as C, C++ and assembly. -
Re: Starting and Stopping Repository Mgr Service
John,
Try this
Shutdown 0
from the Escript.
Herman Magno
Credit Lyonnais, NY
Hello All,
I am running Forte 3.0.D.0 on Windows NT 4.0. At night, I run batchfiles to backup and clean the repository.
>>
With previous versions of Forte (before 2.H) my scripts simply did anrpstop, rpcopy, rpclean and finally a rpstart to start the repository again.
This worked great.
>>
Now, however, I am running the Repository Manager as an NT service, soI can no longer run rpstop or rpstart (rpstart does not start the Repository
Manager service).
>>
One solution I have found is to use Net Stop and Net Start to stop andstart the Repository Manager service, so my script looks something like
this:
>>
rpcopy...
net stop "Forte Repository Manager 3.0.D.0"
rpclean...
net start "Forte Repository Manager 3.0.D.0"
This seems to work fine most of the time, but occasionally the servicewon't stop or start (like when a workspace is open). My questions are:
>>
1) Are there any other command line processes that people knowof to start and stop a service?
>>
2) What is Forte's recommended process for starting andstopping the Repository Manager service in a script?
>>
>>
Thanks for your help
John Bruning
IBIS Consulting Inc.
www.ibis-consulting.comYour object could actually bind to a port using serverSocket.accecpt() and when a connection comes in, it exists.
-
Is there a way to Start and Stop OC4J through Services
Currently we are starting and stopping OC4J manually through the Dos command prompt on our servers. We are interested in making it a Services where we can start and stop OC4J thourgh the services option on the control panel in windows. Any suggestions would be greatly appriciated.
Thanks!
ChadThis has been discussed several times in this forum. One of the thread is
How can I set the export path in Form Builder 6i?
yes, you can use Windows Resource Kit or some third party freeware to do so.
regards
Debu -
Starting and Stopping Repository Mgr Service
Hello All,
I am running Forte 3.0.D.0 on Windows NT 4.0. At night, I run batch files to backup and clean the repository.
With previous versions of Forte (before 2.H) my scripts simply did an rpstop, rpcopy, rpclean and finally a rpstart to start the repository again. This worked great.
Now, however, I am running the Repository Manager as an NT service, so I can no longer run rpstop or rpstart (rpstart does not start the Repository Manager service).
One solution I have found is to use Net Stop and Net Start to stop and start the Repository Manager service, so my script looks something like this:
rpcopy...
net stop "Forte Repository Manager 3.0.D.0"
rpclean...
net start "Forte Repository Manager 3.0.D.0"
This seems to work fine most of the time, but occasionally the service won't stop or start (like when a workspace is open). My questions are:
1) Are there any other command line processes that people know of to start and stop a service?
2) What is Forte's recommended process for starting and stopping the Repository Manager service in a script?
Thanks for your help
John Bruning
IBIS Consulting Inc.
www.ibis-consulting.comYour object could actually bind to a port using serverSocket.accecpt() and when a connection comes in, it exists.
-
Problem with Start or Stop of Portal Service from outside the portal
Hi ,
Can we manage(start and stop) the portal sevice, which is implemented by IService from out side the portal like Visual Administrator or any other.
Please let me know if any solution for this.
Thanks in advance
Tatayya Msolved myself
-
Why do videos from the internet start and stop, Why do videos from the internet start and stop
When I try to watch even a short video from the internet, it starts and stops....its annying....any ideas?
Maybe the speed of your internet connection has some bearing on it?
But you could give this a try - reset Safari and see if that helps at all.
Go to Settings>Safari>Clear History, Cookies and Data. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button. -
Starting and Stopping OBIEE 11g services in AIX
Helllo Experts
Could you pls. let me know how to start and stop OBIEE11g services in AIX.
Here I mean , do I need to update my . profile with all the paths OR setDomainEnv.sh will take care of that.
How to start Admin and BI server, Node manager ......what is the exact nohup command , do I need to put some parameter while starting Admin and Managed server.
Regds
ShahzadHello User,
Below the way you can start:-
To start the Weblogic Server:-
Go to the below directory location
$OBIEE_HOME /user_projects/domains/bifoundation_domain
Command:
$nohup sh ./startWebLogic.sh -Dweblogic.management.username=weblogic -Dweblogic.management.password=<Password> > wls_start.log &
$tail –f wls_start.log
To start the Node Manager:
Go to the below directory location
$OBIEE_HOME/wlserver_10.3/server/bin
Command:
$nohup ./nodemanager.sh &
To Start OPMNCTL:
Go to the below directory location
$OBIEE_HOME /instances/instanceN/bin
Command:
./opmnctl startall
./opmnctl stopall
./opmnctl status
Please mark helpful/Correct.
Thanks,
OBIEELearner. -
How to start and stop Oracle Application Server from ANT
How to start and stop Oracle Application Server and Web application from ANT
Thanks in Advance.
ManiHi,
You can use: startManagedWebLogic.sh, it is in your domain directory and you have to execute it in this way
./startManagedWebLogic.sh managedServerName http://adminServerHost:adminServerPort
For instance, in my case I use:
unixserv01:/webportal/domains/appServerWeb/bin>startManagedWebLogic.sh managedServ01 http://pelma3w3per01.mesaperu.next:7001
You have to run it on the machine where the managed server was installed.
Best regards,
Raúl -
Run windows services from java application
can java application run a windows server
i have a web server that runing using tomcat and mysql
can i make a icon in the systray
that give me the option to (using a menu)
run the server ,wicth means : tomcat and mysql are runing
stop the server
get tomcat stacktrace in a window
i was thinking about runing tomcat and mysql as services
and write the systray application using java,
the systray application should acces window services ,
and run/stop requierd services.
what happend on a machine thar runs linux?
thanks
shayOk .so it's will be a diffrent way under linux..
for systray i will use http://systray.sourceforge.net/
and for services i'll use the
"net start <Service>" and "net stop service"
i need to keep track on the service status
so my Systray status will be updated
what is the command for getting the status of the proccess
thanks shay -
Running and stopping a batch script from Java
I have a requirement in whcih I need to run a batch script which in turn calls another java progam. Now I am using following code which successfully calls batch script and consequently the batch script calls the another java program and batch script exits.
public static void main(String[] args)
try {
Runtime.getRuntime().exec("cmd /c start c:\\temp\\test.bat" );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}Now I am developing this a a client-server application on socket programming. Now after some time I need to stop that java program started by batch script. How can I do it? As per my understanding the call "Runtime.getRuntime().exec("cmd /c start c:\\temp\\test.bat" );" kick starts two processes. One the cmd command and another java command ran by test.bat. Now the how to relate the cmd window to the java cmd started by test.bat and how can i send a ctrl+C command to this cmd window so as to close the underlying running java program.
Please advise.
ThanksHi Steve,
Well, I'm having a quite different opinion on this: I would consider such an appraoch not nice but rather dirty...
If you want users to execute (MaxL) commands against essbase but also would like to avoid installing the client software on each client box I would recommand using web services.
User opens a browser, press a button, button (on the server side) calls a cmd (or sh) that calls the MaxL shell (on the server) that executes your maxl scripts.
We have implemented this in two ways:
1. over IIS (the older version, some years ago - but still running)
2. over Apex (ever heard about it?) You need a Oracle DB where Apex is installed an running (latest Version is 4.1.1 and you should not use an older) and you need to install the essbase client software on the machine where th Oracle DB resides - However you only need to install it one time...
If you only want to use the Oracle DB as a relais station (for you Apex Application and Web calls) you can simply install an XE on your essbase server and you have the prerequisites to get it work.
Maybe it helps somehow.
Regards
Andre
Maybe you are looking for
-
How do i update the timeline index in fcpx?? I kind of deleted a keyword collection and added a new one in the Event library, but it is not showing in the timeline index...Could someone tell me how to do that???
-
When i click on my app it loads a little but then it will go back to the home page what can i do without deleting the app?
-
Premiere Pro CC not using all resources... 4k
I just put together a new workstation machine for editing 1D-C 4k files in Premiere Pro and After Effects. Specs... i7 3770 3.4 Gigabyte Z77 Mobo 32gb Corsair Vengance DDR3 1600 RAM 250gb Samsung SSD 4x 2TB Seagate 7200 HDDs in RAID 0 (Yes I know
-
HT201250 How do you browse other time machine backups of other drives?
It seems to me that Time Machine used to display an option to "Browse other Time Machine backups." For example, my iMac has its Time Machine external drives attached to it. Both my iMac and my MacBook Pro back up to it, though my MacBook Pro does so
-
Why do all of my previously purchased app say they are no longer available?
Each time I try to download a previously purchased app, a message says it is no longer available. It even happens with my movies I've purchased. Is iCloud down or something?