Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过使用Java在powershell中获取processname和id来区分系统进程和正常进程_Java_Powershell - Fatal编程技术网

如何通过使用Java在powershell中获取processname和id来区分系统进程和正常进程

如何通过使用Java在powershell中获取processname和id来区分系统进程和正常进程,java,powershell,Java,Powershell,这是我的密码: 公共类powershell命令{ 公共静态void main(字符串[]args)引发异常{ PowerShellCommand调用=新建PowerShellCommand(); ids=(call.commandsilent(“powershell.exe获取进程|格式表`Id”); 进程=(call.commandsilent(“powershell.exe获取进程|格式表`ProcessName-AutoSize”); } 字符串命令静默(字符串命令)引发异常 {字符串输出

这是我的密码:

公共类powershell命令{
公共静态void main(字符串[]args)引发异常{
PowerShellCommand调用=新建PowerShellCommand();
ids=(call.commandsilent(“powershell.exe获取进程|格式表`Id”);
进程=(call.commandsilent(“powershell.exe获取进程|格式表`ProcessName-AutoSize”);
}
字符串命令静默(字符串命令)引发异常
{字符串输出=”;
//String command=“powershell.exe您的命令”;
//获取版本
//command=“powershell.exe获取进程”;
//执行命令
Process powerShellProcess=Runtime.getRuntime().exec(命令);
//获得结果
powerShellProcess.getOutputStream().close();
弦线;
//System.out.println(“标准输出:”);
BufferedReader标准输出=新的BufferedReader(新的InputStreamReader(
powerShellProcess.getInputStream());
而((line=stdout.readLine())!=null){
输出+=行+“,”;
//系统输出打印项次(行);
}
stdout.close();
//System.out.println(“标准错误:”);
BufferedReader stderr=新的BufferedReader(新的InputStreamReader(
powerShellProcess.getErrorStream());
stderror=“”;
而((line=stderr.readLine())!=null){
stderror+=行;
//系统输出打印项次(行);
}
stderr.close();
//系统输出打印项次(“完成”);
返回输出;
}
}
我在字符串数组processs[]中获得了进程id,在字符串数组ids[]中获得了进程id


但是我找不到任何方法来区分它们。

只需运行方法commandsilent(“powershell.exe获取进程-IncludeUserName |选择对象Id,用户名”);在main()方法中。

是否有powershell命令来区分正常进程和系统进程?我目前正在区分,因为它在commandsilent(“powershell.exe Stop Process-ID”+ID)上给出了一个错误,如果它是一个系统进程,则会关闭该进程。如果能提供进一步的帮助,我们将不胜感激。
获取进程-IncludeUserName
?这是可行的,但我只需要用户名并使用特定进程的id或进程名。
获取进程-IncludeUserName |选择对象id,用户名
?或者在单独的数组中:
(获取进程-IncludeUserName).Id
(获取进程-IncludeUserName).Username