0

For running a java code (that includes a JXInput code for a Joystick use), I only run this .bat: jre1.8.0_66\bin\java.exe -Djava.library.path=d:\HG -jar HG11.9.jar

But, that works if I has PREVIOUSLY installed the VC redistributable.

As some people are not software specialists, they don't know how to install this vc_redist_.exe from https://www.microsoft.com/en-US/download/details.aspx?id=48145. I mention "" because it depends on the system they have (vc_redist.x64.exe or vc_redist.x86.exe).

I am sure that this problematics consisting in facilitating procedure of installation of a game and, more generally, a product has been already solved. So, what is the good practice to manually avoid to install the vc_redist?

In other words, is it possible to include this vc_redist in the .jar? Then, only running a .bat (like above) allowing to run the game.

If not, is it possible to run a single .bat or something else that: - unzip the .zip file of my game (this file includes the game and the vc_redist) - then automatically install the vc_redist, depending on the system (32 or 64 bits) - by what means?

Thanks a lot for your response

Pascal DUTOIT
  • 121
  • 1
  • 13
  • The redist can be silently installed from command line using commands found [here](http://asawicki.info/news_1597_installing_visual_c_redistributable_package_from_command_line.html). Use the env var `PROCESSOR_ARCHITECTURE` to determine if the 32 or 64 bit version should be installed. – bgfvdu3w Jan 22 '18 at 06:58

1 Answers1

0

If you already have bat file for install best way to do this will be to include install of vc_redist in this *.bat before install. From what I know it is not posiible to include this in the *.jar. Better will be to pack all files into zip (together with this *.bat script).

To install vcredist in bat silently you will have to add these commands:

@echo OFF
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT

if %OS%==32BIT runas /user:Administrator %~dp0\vcredist_x86.exe /q /norestart
if %OS%==64BIT runas /user:Administrator %~dp0\vcredist_x64.exe /q /norestart

#rest of your script

Checking if system is 32bit of 64bit is taken from here (batch file to check 64bit or 32bit OS)

%~dp0 resolves to the full path of the folder in which the batch script resides.

Edit:

As the runas might not be the best solution to problem of running this as administrator I will direct you to these posts to read about running with administrator privilages in bat

How to code a BAT file to always run as admin mode?

How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?

wdudzik
  • 1,264
  • 15
  • 24
  • 1
    Remember, it's installation will require admin privilege. – Asesh Jan 22 '18 at 07:09
  • The simple solution would be to write instruction to run installation script as administrator. I updated answer with solution of runas that should work. – wdudzik Jan 22 '18 at 07:14
  • @ketjow4: "what means "%~dp0". Is it the microsoft URL mentioned in my question ? If I include these two .exe files in my zip, in d:/hg location, what is the .bat command for installing it? Thanks – Pascal DUTOIT Jan 22 '18 at 12:52
  • @PierreDurand it is not an microsoft url. You will have to zip all your files. Then you will unzip your files ( this vcredist_x64.exe, vcredist_x86.exe, *.bat and some *.jar files) on another machine or in some other folder. So to easily locate your exe and other files it would be good to make all filepath relatives and that is what `%~dp0` does. As it is in my answer it will get the path to where *.bat file is located so after unziping you can just run it :) – wdudzik Jan 22 '18 at 13:23
  • @ketjow4 ok. What is the problem if I replace "%~dp0\" by ""? In other words, replace "%~dp0\vcredist_x86.exe' by "vcredist_x86.exe" because the .bat file will be at the same place than these .exe files and the .jar. – Pascal DUTOIT Jan 23 '18 at 06:51
  • If you try to right click and run as administrator it will not work (because the current directory is changed to C:\Windows\System32 instead of where the batch file actually is). So it is just safer to use it because it will always work :) – wdudzik Jan 23 '18 at 07:03