How to stop a windows process in java program?

Thanks!

Write a JNI function that uses the APIs OpenProcess and TerminateProcess.
Beware - not all processes can be terminated by the TerminateProcess API. To prove my assertion, try killing some processes using the Task Manager. Even running your program as an administrator, you can't kill processes like Windows services.

Similar Messages

  • How to stop a windows process?

    How do I get hold of a running process/program under WindowsXP?
    How do I stop this process?
    # Johannes

    You should use the Java Native Interface and write some C code with the Win32 API. I don't think there is another way. You should search the MSDN for code samples for killing windows processes. And if you go ahead and do what i just suggested, then i wish you good luck and be patient!

  • Need to track windows processes through java code.

    Need to track windows processes through java code.
    Eg: I want to find out whether an exe file (wrun.exe) is running or stopped.
    Can I do it through java. If so can any one please tell me how to do it. That will be a great help.
    Thanks,
    Ramesh

    There are 2 options for things like this:
    1) Use Runtime.exec() to execute some command or application and parse the input from it.
    2) Write some native code and use JNI to call it.

  • 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

  • How to stop the running process chain

    How to stop the running process chains or infopackges...just qm status change is enought?

    BI - SM 37 - Kill the Job
    ECC - SM 50 - Kill the job

  • How to stop the backup process....

    How to stop the backup process....
    Okay, so it happens nearly everytime you synch your iPhone with your iTunes? Easy. As soon as it starts, hit the "X" in the bar where the backup process is being shown, this does NOT STOP the synching process, ONLY the backup process.
    HOWEVER, keep in mind that a few times during the week (depends how often you synch ur iPhone) it will be good to let the backup process let run fully.
    There we go. Problem solved...

    i agree its what i do i backup whenever i add a new app, or take more pics etc its exactly what i do its what ive been saying on all these threads talking about backups etc, im hoping in 2.0.1 will be bug fixes about this sort of thing...

  • How to call a external software in java program?

    for example, if I want to execute internet explore or windows word in java program, how to do it?

    // Modified from Just Java
    import java.io.*;
    public class execDir {
    public static void main(String args[]) {
    try {
    Runtime rt = Runtime.getRuntime(); // step 1
    Process prcs = rt.exec("doDir.bat"); // step 2
    InputStreamReader isr = // step 3
    new InputStreamReader( prcs.getInputStream() );
    BufferedReader br = new BufferedReader( // step 4.
    isr );
    String line;
    while ((line = br.readLine()) != null)
    System.out.println(line);
    } catch(IOException ioe) { System.out.println(ioe); }
    Maybe this will help you.

  • How to connect iseries green screen from java program

    how to connect iseries green screen from java program to get the data in the DB files ,here the DB is DB2/400

    Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
    import java.io.*;
    import java.net.*;
    public class AutoTelnet {
         private static Socket s;
         public static void main(String[] args) throws Exception {
              Thread t = new Thread() {
                   @Override public void run() {
                        try {
                             s = new ServerSocket(5555).accept();
                        } catch (IOException ex) {
                             ex.printStackTrace();
              t.start();
              Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
              t.join();
              PrintStream ps = new PrintStream(s.getOutputStream());
              ps.println("Screen will be cleared in 5 seconds");
              ps.println("5");
              Thread.sleep(1000);
              ps.println("4");
              Thread.sleep(1000);
              ps.println("3");
              Thread.sleep(1000);
              ps.println("2");
              Thread.sleep(1000);
              ps.println("1");
              Thread.sleep(1000);
              ps.println("\u001b[2J");
              Thread.sleep(5000);
    }

  • How to stop an ORB server in other program

    I have writen an ORB server program, just like the sample HelloServer, the main thread wait on a new object forever.
    How to stop the server in some other programs?
    Is there some common method to stop ORB server except kill the main process.
    Thank for any help!

    The question I have is how to stop an orb server programmatically without shutting down my app. My app is a server that runs continuously. I want the ability to shut down just the orb portion and restart it if desired.
    I also look for this capability. When searching for this in the forums, surprisingly, I only find one question for this, but no reply or answer. Does anyone have any idea?
    Thank you for all ideas.

  • How to call SAP Webservice in standalone java program

    Hi,
    In our Java application, we want to use the SAP Webservices. I dont know much about authentication mechanism used by SAP. Can any one please help me with any sample code how to Call SAP webservice in Standalone Jave Program. I searched alot on the web regarding this, but helpless. Please help me.
    Thanks,
    Mohan

    Hi Mohan,
    You need an account for the ES Workplace. I'm afraid this is not free, e.g. check [SAP NetWeaver, Composition Subscription|https://www.sdn.sap.com/irj/sdn/subscriptions/composition].
    But I thought you wanted to play with a WSDL [you already had at hand|Sample code to access BAPI Web services from JAVA required;?

  • How to create an Oracle DATABASE through Java Programming Language.. ?

    How to create an Oracle DATABASE through Java Programming Language.. ?

    Oracle database administrators tend to be control freaks, especially in financial institutions where security is paramount.
    In general, they will supply you with a database, but require you to supply all the DDL scripts to create tables, indexes, views etc.
    So a certain amount of manual installation will always be required.
    Typically you would supply the SQL scripts, and a detailled installation document too.
    regards,
    Owen

  • PFRD 11.1.1.4 - How to stop the In-process Reports Server

    I'm running an "out-of-the-box" PFRD 11.1.1.4 installation in Windows XP SP3.
    According with documentation:
    http://docs.oracle.com/cd/E17904_01/bi.1111/b32121/pbr_strt006.htm#BEHDJFHD
    To directly start or stop the in-process Reports Server using a URL, enter the following in your Web browser:
    http://machine_name:port/reports/rwservlet/startserver
    http://machine_name:port/reports/rwservlet/stopserver
    startserver works.
    stopserver returns:
    REP-50171 : Authentication failed.
    Tried
    http://machine_name:port/reports/rwservlet/stopserver?authid=weblogic/passwd
    same error.
    Commented the line:
    <!--security class="oracle.reports.server.RWJAZNSecurity" id="rwJaznSec"/-->
    in rwserver.conf.
    Same error.
    The only uncomented elements in "rwservlet.properties" (original configuration) are
    <server>rep_wls_reports_pfurtado-lap_asinst_1</server>
    <singlesignon>no</singlesignon>
    <inprocess>yes</inprocess>
    Did any of you managed to stop "in-process" reports server using the reports servlet?
    What credentials did you use?
    Thanks & Best Regards
    Paulo

    Thanks RZ!
    The line you mentioned was already as you described.
    According with the documentation:
    [Starting and Stopping Reports Server|http://docs.oracle.com/cd/E17904_01/bi.1111/b32121/pbr_strt001.htm#i1005629]
    If Reports Server is running as an in-process server through the Reports Servlet, issue the following URL:
    http://your_host_name:port_number/reports/rwservlet/stopserver?authid=admin user/admin password
    Note:
    authid is Reports Server's administration user name and password. In Oracle Reports 11g Release 1 (11.1.1), the default security is based on standards-based Java EE security model through Oracle Platform Security Services. For a non-secure Reports Server, this user is defined in the identifier element.
    I added the identifier element to rwserver.conf and restarted WLS_REPORTS, but after this the in-process reports server failed to start with the usual generic exception.
    I finally found the missing step in:
    How To Secure Showjobs Web Command In A Non Secured Reports Server In Oracle Report 11g? (Doc ID 1242614.1)
    The thing is that the identifier element has to be placed in the right location inside rwserver.conf:
    The needed change is:
    FROM
    <queue maxQueueSize="1000"/>
    <pluginParam name="mailServer" value="%MAILSERVER_NAME%"/>
    TO
    <queue maxQueueSize="1000"/>
    <identifier encrypted="no">....type here your user/password....</identifier>
    <pluginParam name="mailServer" value="%MAILSERVER_NAME%"/>
    So although using the default non-secure reports server, the identifier element has to be present in rwserver.conf for rwservlet/stopserver to work as described above.
    Otherwise the needed authentication will fail as described.
    Regards
    Paulo

  • How to execute external  spawned process using  java

    Hi,
    I am executing PGP from command line using java.
    For adding the public key I use Runtime object like this
    Runtime rt = Runtime.getRuntime();
    Process process = rt.exec("pgp -ka "+"d:/Mangesh/pubkey/sandy.asc "+"C:/PROGRA~1/NETWOR~1/PGPNT/keyrings/pubring.pkr");PGP is executing this but inbetween it asked for confirmation "Do you want to add public key (y/n)"
    I am providing data to process this way:
    PrintWriter pw = new PrintWriter(new OutputStreamWriter( process.getOutputStream()));
    pw.write('y');
    pw.flush();But after this their is no execution from PGP and console remains until I closed it.
    PGP is waiting for ENTER KEY
    How can I provide ENTER KEY from java
    This is right method ??? or any other options are available??
    I am awaiting for your valuable suggestions .
    Regards
    Man479

    On Windows the "enter key" consists of two characters: carriage return and a line feed (\r\n). You may have to send both. If that doesn't work, pgp is not reading the reply through stdin, only through the console, and there's no way to pass the 'y' to it through Java.

  • Possible to manage Windows processes using Java

    Hi,
    I'm looking to develop a standalone application that will be able to kill certain Windows processes...is such a thing possible using Java? If not, could someone point me in the direction of a technology that can achieve this?
    Thanks

    [LEARN HOW TO RESEARCH YOURSELF!!! THEN ASK QUESTIONS LATER|http://tinyurl.com/yllkh3v]
    Mel

  • How to call a BPEL process from Java ?

    How can I call a BPEL process from Java?
    The Java client should be outside of the PEL engine.
    Does someone have a piece of sample code for
    a "Hello world" java-to-bpel call (+ java client src)?

    http://www.oracle.com/technology/products/ias/bpel/pdf/orabpel-Tutorial7-InvokingBPELProcesses.pdf

Maybe you are looking for