は、プロセスをチェックするための完全なコードは、(すでに開いているかいない 機能CheckApplicationIsOpen.isOpenApplicationです)状態を返しているPowerPointのexeファイルをチェックし、メインに 「開く」または「閉じる」スタートですPowerPointが開いている場合
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package checkapplicationisopen;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author ANGEL
*/
public class CheckApplicationIsOpen {
/**
* @param args the command line arguments
*/
/***
*
* @param applicationName : whatever application you want to check if it is already open or not
* @return the result status if it is open then 'open', otherwise 'close'
*/
public static String isOpenApplication(String applicationName)
{
String result="";
try {
String line;
String pidInfo ="";
Process p =Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
pidInfo+=line+"\n";
}
System.out.println("Data : "+pidInfo);
input.close();
if(pidInfo.contains(applicationName))
{
System.out.println(applicationName+"is open");
result="open";
}
else
{
System.out.println("PowerPoint is Not Open");
result="close";
//
}
} catch (IOException ex) {
Logger.getLogger(CheckApplicationIsOpen.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}
public static void main(String[] args) {
try
{
if(!CheckApplicationIsOpen.isOpenApplication("POWERPNT.EXE").equals("open"))
{
Process p1=Runtime.getRuntime().exec("cmd.exe /C start powerpnt");
}else
{
System.out.println("Application is Open");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
おかげで多くのことをタスクマネージャのインスタンスを使用することのないsandip.Butまた、私は何もあればしたいんhappens.I PowerPointが、その後実行されている場合、それはあなたのコード内top.hereに表示されなければならないことを望みます可視性よりも開いているパワーポイントを真に設定する必要があります。 –
PowerPointは単独のインスタンスのみを許可するので、現在開いているインスタンスがある場合はそのインスタンスを取得するか、新しいインスタンスを開始します。注意すべき唯一の奇妙な点は、PowerPnt.EXEのインスタンスがクラッシュして完全には閉じられていないか、ユーザーがWindowsエクスプローラでプレビューペインが表示されていて、PPTが開いているためです。プレビューウィンドウ –