Detect if certain software is installed on a user's machine in Java

后端 未结 4 1291
时光说笑
时光说笑 2020-12-20 00:53

I have a Java application which requires certain software (one of them being Perl) before it can be run. What I used to do to detect for Perl is:

Runtime.get         


        
4条回答
  •  无人及你
    2020-12-20 01:13

    Getting windows native information using java SDK is not possible without support of external APIs. Instead of using external APIs (which is mostly LGPL licensed and not completely open), we can use the shell commands to get the same.

    Step 1 - Checking if (perl) an application is installed

    For checking if an application is installed, use ProcessBuilder or Runtime.exec to run one of the following PowerShell command,

    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* | Select-Object DisplayName | where {$_.DisplayName -match "perl"}

    Replace "perl" with your choice of software and stream the output of these and process it.

    If PERL (for above question), follow below 2 steps to set path and run perl script from java

    Step 2 - If available, set it to Environment Path using java code.

    Step 3 - Run your perl script.

提交回复
热议问题