0

I am creating an application where I need java jdk to be installed.

So I want to create a detection function for jdk in system and if not found then install it by the setup which i will provide and also store it Environment Variables -> System variables as JAVA_HOME C:\Program Files\Java\jdk1.x.y.z by default.

I searched through lot but not getting exact idea how will I achieve this.

WhoAmI
  • 217
  • 1
  • 2
  • 23
  • This question is a bit confusing. Are you wanting to use JavaScript and Angular to do this? – Peter Mellett Oct 04 '18 at 10:23
  • Is there any reason about tagging javascript and angularjs here? This seems to be java-related, rather than javascript-related. – briosheje Oct 04 '18 at 10:26
  • @PeterMellett yes, that's correct . I need Angular javascript/javascript function to achieve this. – WhoAmI Oct 04 '18 at 10:27
  • @briosheje This is angular app. I want to do the task using javascript function. – WhoAmI Oct 04 '18 at 10:28
  • Do you mind expanding your question a little? How are you running your angular app? – Peter Mellett Oct 04 '18 at 10:28
  • @PeterMellett I am creating desktop application using Electron and AngularJS. I am running it by node/ electron command. – WhoAmI Oct 04 '18 at 10:29
  • @WhoAmI Ok, tagging electron is indeed very important at this point. – briosheje Oct 04 '18 at 10:30
  • You can check this for instance: https://stackoverflow.com/questions/19734477/verify-if-java-is-installed-from-node-js which will help you check whether java is installed or not. You can run any node script from electron's main process, then talk with the renderer through the IPC channel so that you are aware about whether java is installed or not. – briosheje Oct 04 '18 at 10:31
  • @briosheje ok let me try. – WhoAmI Oct 04 '18 at 10:32
  • @briosheje This gives me JRE version . I need to check JDK is installed in the system or not. – WhoAmI Oct 08 '18 at 06:49
  • @WhoAmI with electron, from the **main** process, you can spawn a shell, and execute `javac -version`. Check this: https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js . The base concept is that you can run a shell command, so you can easily check whether the JDK is installed or not directly from there. – briosheje Oct 08 '18 at 06:52
  • @briosheje Ok I got it. Thanks – WhoAmI Oct 08 '18 at 06:56
  • (BEWARE of security issues though, avoid injecting dynamic parameters in the shell command, otherwise be careful). – briosheje Oct 08 '18 at 07:11
  • @briosheje when I am trying to run `.spawn('javac', ['-version']);` according to this, gives me no output. – WhoAmI Oct 08 '18 at 08:05

1 Answers1

0

I need to know more about your app, which Angular or Nodejs as the backend of your app and if angular then you need to use ironic or some similar hybrid technology for accessing system level permission like installing software and updating Environment Variables. If you are using NODEJS as backend then you can use exec to execute system command and also you can install your JDK with silent installation refer the link

Anuragh KP
  • 748
  • 11
  • 21
  • Ok . I am using Node.JS as backend. I have an idea of `child_process` . silent installation will only install silently. I need to set the path also in Environment variables automatically. First search jdk ,if found then skip, not found install silently and put it in Environment Variable. – WhoAmI Oct 04 '18 at 10:57
  • 1
    The MSDN documentation for environment variables tells you what to do: To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates. You will of course need admin rights to do this. I know of no way to broadcast a windows message from Windows batch so you'll need to write a small program to do this. – Anuragh KP Oct 04 '18 at 12:26
  • https://learn.microsoft.com/en-gb/windows/desktop/ProcThread/environment-variables please read the link – Anuragh KP Oct 04 '18 at 12:29