How to kill a system process from java code.

Hi,
i need to kill or remove windows system process like cmd.exe from java code.
like removing it from end process in task mgr.
i tried below code but its not removed.
is there a better way we can do this.
killing a system process from java code will create any issues?
   public static void main(String[] args) throws Exception {
   String[] cmd = { "cmd.exe" };
   Process p = Runtime.getRuntime().exec(cmd);
   p.destroy();
any suggestions or ideas are really appreciated.
thanks.

Hi  jtahlborn, mohan
yes the process is created from my java code. 
in my code iam creating a process like below and if it is running for a long i need to kill it from java.
For that " Runtime.getRuntime().exec("taskkill /F /PID " +  7408); " is working fine.
7408 is my process id in taskmgr created from java and iam manually passing the PID it to kill it.
But i need to get the PID from java code.
Thanks for your suggestions.
Sample Code:
public static void main(String args[])
        try {
          Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","start"});        
          Field f = process.getClass().getDeclaredField( "handle");
          f.setAccessible( true);         
          long procHandle = f.getLong( process);
          System.out.println( "prochandle: " + procHandle );
          //Runtime.getRuntime().exec("taskkill /F /PID " +  procHandle);
        } catch( Exception e) {
          e.printStackTrace();

Similar Messages

  • How can I set system date from java code?

    Hi. I need to set the system date from my application. It must works on Windows7 so the "cmd /C date" must be executed with Administrator privileges.
    I tried do it that
    Process p = rt.exec("runas /user:" + env.get("COMPUTERNAME") + "\\Administrator \"cmd /C date " + dateYYYYMMDD + "\"");
    Then process ask me for password for administrator but it terminates befor i send it. exitCode() returns 1.
    Have you some idea how can I do it?
    Regards for you.

    At the very least, you need to read this and follow the advice it gives. That may or may not solve your problem, but it's a bare minimum.
    http://www.javaworld.com/jw-12-2000/jw-1229-traps.html

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • Ttrigger Event Sub-Process from Java code.

    Hi All,
    Is there any way to trigger Event Sub-Process from Java code.
    My requirement is to trigger an Event SubProcess when a Approver clicks on REJECT button in HUMAN TASK.
    One way of achieving this is by placing a gateway after the human task and by validating the human task outcome and there by triggering a call to Event SubProcess.
    But we dont want to put a gateway after the human task. But instead we would like to trigger the Event SubProcess from the ADF task forms itself. ie, by calling a JavaCode.
    Please give me some pointers on achieving this task.
    Thanks
    Parker.

    Hi  jtahlborn, mohan
    yes the process is created from my java code. 
    in my code iam creating a process like below and if it is running for a long i need to kill it from java.
    For that " Runtime.getRuntime().exec("taskkill /F /PID " +  7408); " is working fine.
    7408 is my process id in taskmgr created from java and iam manually passing the PID it to kill it.
    But i need to get the PID from java code.
    Thanks for your suggestions.
    Sample Code:
    public static void main(String args[])
            try {
              Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","start"});        
              Field f = process.getClass().getDeclaredField( "handle");
              f.setAccessible( true);         
              long procHandle = f.getLong( process);
              System.out.println( "prochandle: " + procHandle );
              //Runtime.getRuntime().exec("taskkill /F /PID " +  procHandle);
            } catch( Exception e) {
              e.printStackTrace();

  • How to find the  System Dbtype in java code

    How to find the System Dbtype in java code
    I need various Db connection my project (oracle, sq l,sybase,db2),So How to find the System Dbtype in java code

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • 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

  • How to find particular CRM BAPIs from Java code of ISA B2B application?

    Hi Guys,
    I am newbie in CRM ISA field. I am supporting CRM ISA 5.0 B2B application.
    Basically I had a question about how to go about finding the BAPIs which are getting called from the Java side of ISA.
    I know that the framework uses JCO connection in order to execute BAPIs in the back-end and usually these BAPIs are standard.
    So I can put a break-point on the CRM bapis and see which is called when.
    But if I want to track BAPIs from Java code, what should be my approach?
    Please help.
    Thanks!

    Hi,
    To setup the trace logs you need to use the following URL.
    https://<system domain name>:port/<application_name>/admin
    typically it should look like as below:
    https://abc.com:50001/b2b/admin
    Here there is an option to start and stop the logs and after stopping it will generate a Zip file which you need to download and from there you can easily find out the BAPI's or teh RFC calls.
    Also when you search you should alwways keep one thing mind that these FM's normally start with CRM_ISA*
    Hope it helps.
    Regards
    Sidd

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

  • DOS 11g SOA have the Locator API's - How to Invoke a BPEL process from Java

    In BPEL 10.1.3.1, a java client could use the "Locator" API's to look up a BPEL service and invoke it directly from Java,
    Is that still present in SOA 11g ? Or is there another way to look up the BPEL process ...
    Here's an example of the 10g BPEL Service locator facilities :
    Get the BPEL service locator. This is retrieved as follows:
    loc = new Locator(domain, domainPassword);
    The initial installation BPEL domain is "domain" and the initial password is "bpel". We then use the locator to get the delivery service. We could also use the locator to retrieve the workflow service.
    IDeliveryService svc = (IDeliveryService)loc.lookupService(IDeliveryService.SERVICE_NAME);
    Now we have the delivery service we can "deliver" requests to the BPEL process. To do this we first need to create a new message.
    NormalizedMessage msg = new NormalizedMessage();
    String content = "<SyncHelloWorldProcessRequest xmlns=\"http://antony.blog/SyncHelloWorld\">"+
    "<input>"+
    name+
    "</input>"+
    "</SyncHelloWorldProcessRequest>";
    msg.addPart(msgPart, content);

    Can you please tell me how to include adf binding.ws in composite.xml ? My composite.xml for your ref:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- Generated by Oracle SOA Modeler version 1.0 at [11/1/10 5:41 PM]. -->
    <composite name="BPEL2"
    revision="1.0"
    label="2010-11-01_17-41-11_593"
    mode="active"
    state="on"
    xmlns="http://xmlns.oracle.com/sca/1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy"
    xmlns:ui="http://xmlns.oracle.com/soa/designer/">
    <import namespace="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1"
    location="BPELProcess1.wsdl" importType="wsdl"/>
    <service name="bpelprocess1_client_ep" ui:wsdlLocation="BPELProcess1.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1#wsdl.interface(BPELProcess1)"/>
    <binding.ws port="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1#wsdl.endpoint(bpelprocess1_client_ep/BPELProcess1_pt)"/>
    </service>
    <component name="BPELProcess1">
    <implementation.bpel src="BPELProcess1.bpel"/>
    </component>
    <wire>
    <source.uri>bpelprocess1_client_ep</source.uri>
    <target.uri>BPELProcess1/bpelprocess1_client</target.uri>
    </wire>
    </composite>
    Eric, when I select the BPEL wsdl file in "Create Web Service Data Control" wizard, immediately I am getting the error. When I click 'OK', the 'Service' dropdown is disabled and blank in the wizard.
    Thanks for pointing to the sample application URL. But it is built in jdev 10g. Can I migrate it to 11g?
    Thanks both of you!

  • How to kill a system process on terminal

    Be very careful when killing system process with this procedure, use it only if you really have no other choise:
    1- Open Terminal
    2- Type: top on the shell
    3- Find the number of the process you what to terminate Exp: If you what to kill NortonMiss it will be display like this:
    262 NortonMiss 0.0% 0:00.02 1 21 19 68K 540K 436K 27.5M
    4- You can't kill this process, is system protected, you need to logon as superuser, to do this, open an other window of the shell and type:
    sudo kill 262
    (the number of the process is different on each session, and depending on the application or process you what to terminate)
    5- You'll be ask for your password, type it and press enter, the app will be kill! (when typing the password, it will not be display on the screen). To cancel the kill press CTRL+Z
    NOTES:
    Some system process will reboot after they are killed, but this command is usefull if the process hang up, when is rebooted it will work again on most cases.
    A superuser have access to all the process and has no restriction on the use of commands on UNIX. Be sure not to reveal the password of your computer to anybody, because if they logon as superuser on your mac, they can deleted any folder.
    Use very caution on the use of the "sudo" command.
    iMac (Summer 2001) 600Mhz RAM=384MB Slot loading   Mac OS X (10.3.5)   CD-RW, 40 GB hard drive, Slot loading CD-RW

    Well, I only post this as one method, but I know that UNIX is a very flexible OS, so I'm sure there are more ways to kill a process, thanks for sharing them, and...
    NifflerX, Thanks! I didn’t know that one, but I also like the top command, 'cause I can see the process activity as I work, useful to know if the process still hang-up or all of the sudden goes back to life like a nosferatu... hehehe. By the way... all that people that just got their macs after a PC with.... agggghhh... Windows XP (sorry I say that)... you will find that the top command is the counterpart of the Process Viewer that shows up by pressing CTRLALTDEL on the ugly PC keyboard.
    Oh.,. And Daniel Macks, you can cancel the command with CTRL+Z when the prompt asks for your password, only at this point.
    Thanks for the extra tips everyone!
    iMac (Summer 2001) 600Mhz RAM=384MB Slot loading   Mac OS X (10.3.5)   CD-RW, 40 GB hard drive, Slot loading CD-RW

  • How to pass parameters to JasperReports from Java Code !!

    Hi all
    I m working on existing project and struck with a little problem. Though i have created report using iReport tool but i dont know how to integrate my reports with java code and pass suitable parameters.
    Note : To answer this knowledge of jasperreports is must.
    Kind regards
    jitendra

    Note : To answer this knowledge of jasperreports is must.Then Note: you are asking in the wrong place. Try a Jasper Reports forum. Not this site.

  • How to kill a .exe file from java !!

    hi !!
    how can i avoid duplicate use of a .exe file in jva ! i mean how can i kill duplicated copies sothat i wan allow only one copy ( one use ) at once !!
    please help me

    A network port can only be used by one process at a time.
    So you can use this as a marker or lock to tell if your program
    is already running.
    It's a hack, and won't work if anyone else choses the same
    port you do, or if your program doesn't release the socket
    cleanly when it exits.
    amarshwren
    import java.io.IOException;
    import java.net.ServerSocket;
    public class SocketTest
    private static final int LOCK_PORT = 12345;
    // replace this method with whatever you really want to do
    private void doSomething()
    System.out.println("Pretending to do something...");
    try
    synchronized (this)
    while (true) this.wait();
    catch (InterruptedException ex)
    System.out.println("This won't happen.");
    public static void main (String args[])
    ServerSocket lockSocket = null;
    try
    lockSocket = new ServerSocket(LOCK_PORT);
    catch (IOException ex)
    System.err.println("An instance of SocketTest is already running.");
    System.exit(-1);
    SocketTest socketTest = new SocketTest();
    socketTest.doSomething();

  • How to checkout file on SCM from Java code ???

    Hi friends,
    I am developing application for test and trackking project . And I want to checkout my old files and then download.
    I found scm ide but I couldn't find any sample about it. So I am in stuck!!
    any body know, how to use it??
    or any sample, document ??
    thanks alot,

    So you are trying to use the JDeveloper Extension SDK to create integration with a version management tool.
    In that case visit the Extension SDK page on OTN:
    http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/index.html
    You'll see there explanation of how to get the samples:
    http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/samples.html
    Then have a look at the VersionControlRCS sample:
    Sample version control integration using the version control system (VCS) API.

  • How to run system commands from JAVA

    Hi Friends,
    How to run windows system commands from JAVA
    Runtime r=Runtime.getRuntime();
    r.exec("dir");
    Throwing following Exception
    CreateProcess :dir error=2
    Thanks in advance
    Hamsa

    Hi ,
    in Windows NT this is not possible, you can use the following :
    Runtime r=Runtime.getRuntime();
    StringBuffer sbuf = new StringBuffer();
    String dir = new String();
    java.lang.Process proc = r.exec("cmd /c dir");
    InputStream is = proc.getInputStream();
    int ch ;
    while((ch=is.read() ) != -1)
    sbuf.append((char)ch);
    is.close();
    dir = sbuf.toString();
    System.out.println(dir );

  • How to call BPM process from Java

    Hi All,
    Can anybody help how to call a BPMN process from java.Please give any sample exaple on this.
    Thanks,
    Ganesh

    For 11g BPM please look at this post. Re: Getting while running the BPEL process from java
    It references an ATeam example app that can start processes from a web client. But the Java APIs are described too.

Maybe you are looking for