Win7 Next Switch JDK Batch command for

1. Batch file ( Must be performed as an administrator ) The contents are as follows

@echo off
rem --- Base Config To configure JDK Installation directory ---
:init
set JAVA_HOME_1_8=C:\Program Files\Java\jdk1.8
set JAVA_HOME_1_7=C:\Program Files\Java\jdk1.7 :start
echo Currently in use JDK edition :
java -version
echo.
echo =============================================
echo jdk Version list
echo 1.8
echo 1.7
echo ============================================= :select
set /p opt= Please select jdk edition :
if %opt%==1.8 (
set TARGET_JAVA_HOME=%JAVA_HOME_1_8%
)
if %opt%==1.7 (
set TARGET_JAVA_HOME=%JAVA_HOME_1_7%
) echo The current choice Java route :%TARGET_JAVA_HOME% wmic ENVIRONMENT where "name='JAVA_HOME'" delete
wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%TARGET_JAVA_HOME%" rem --- set path ---
set jhb=%TARGET_JAVA_HOME%\bin
set pt=%Path% call set pt=%%pt:%jhb%;=%%
call set pt=%%pt:%jhb%=%% wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue="%jhb%;%pt%" rem Enter the path of the current batch file . because , When processing as an administrator , The current path is %root%Systems32
cd /d %~dp0 rem -- refresh env ---
call RefreshEnv echo Please press any key to exit !
pause>nul @echo on

2. To perform the switch RefreshEnv.exe file (copy To the current folder ): Download and unzip RefreshEnv To the current bat Catalog

remarks

  1. Batch files change environment variables

    • JAVA_HOME, Set to target version JDK route , Administrator privileges required
rem --- set JAVA_HOME ---
wmic ENVIRONMENT where "name='JAVA_HOME'" delete
wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%TARGET_JAVA_HOME%"
  • PATH, increase %JAVA_HOME% Under the bin Path to %PATH% environment variable , Administrator privileges required
rem --- set PATH ---
set jhb=%TARGET_JAVA_HOME%\bin
set pt=%Path%
  1. When running as an administrator , The current path is %System_root%/systems32, The path needs to be

    Switch back to the directory of the current batch file , To run files in the same path RefreshEnv.exe To refresh the environment variables

    • The command to change the path is :

      • cd %~dp0

About %~dp0 A detailed explanation of the batch command

%~dp0 “d” by Drive Abbreviation , That's the drive , disk 、“p” by Path abbreviation , That's the path , Catalog

cd Is to go to this directory , But I think cd /d %~dp0 It's better . Apply to The batch file is not on the system disk .

Option grammar :

~0 - Remove any quotes ("), expand %0

%~f0 - take %0 Expand to a fully qualified pathname (“f” yes file, I.e. documents )

%~d0 - Only will %0 Expand to a drive letter

%~p0 - Only will %0 Expand to a path

%~n0 - Only will %0 Expand to a file name (“n” yes name file name )

%~x0 - Only will %0 Expand to a file extension

%~s0 - The extended path contains only short names (“s” by Short, A short )

%~a0 - take %0 File attributes extended to files (“a” by attribute, The property )

%~t0 - take %0 Expand to the date of the file / Time (“t”time)

%~z0 - take %0 Expand to file size (Size size )

%~$PATH:0 - Find the directory listed in the path environment variable , And will %0 expand

To the first fully qualified name found . If the environment variable name

Undefined , Or no files found , This key combination extends to

An empty string

You can combine modifiers to get multiple results :

%~dp0 - Only will %0 Expand to a drive letter and path

%~nx0 - Only will %0 Expand to a file name and extension

%~fs0 - Only will %0 Expand to a full pathname with a short name

%~dp$PATH:0 - Find the directory listed in the path environment variable , And will %I expand

To the first drive letter and path found .

%~ftza0 - take %0 Extended to a similar output circuit DIR

%0 Create the current batch file

If 0 Switch to 1 For the first file ,2 For the first time 2 individual


%0 Refers to the batch file itself

%~d0 It refers to the drive letter of the batch

%~dp0 It's drive letter plus path

cd /d %~dp0 That is to enter the directory where the batch process is located

reference

Win7 Run the batch file as an administrator , Switch JDK More articles related to the version

  1. VS2005 VS2008 The compiled program is in Win7 To run as an administrator

    stay VS2005 perhaps VS2008  Inside , Right click on the direct project --- attribute --- The connector --- Inventory file ---uac Execution level     choice requireAdministrator   recompile In this way, your program can run directly and have management ...

  2. win7 How to run the command prompt as an administrator (cmd)

    1. Enter into : C:\Windows\System32 2. find cmd.exe file 3. Right click , choice Run as administrator .

  3. Win7 Of “ Run as administrator ”

    If HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA Set to 0, be " Run as administrator " ...

  4. VS2005 The project is in win7 Run with administrator privileges

    Want to close the information http://stackoverflow.com/questions/13030492/set-administrator-privilege-for-my-c-application-in ...

  5. vs2005 ,2008,2010 Introduction in app.manifest( namely c# The program is in win7 Run the method with administrator privileges )

    open VS2005.VS2008.VS2010 engineering , View... In the project folder Properties Is there any app.manifest This file : If not , Create as follows : Right click the project and select... From the menu “ attribute ”, Click work ...

  6. csharp: introduce app.manifest, The program is in win7 Run the configuration method with administrator privileges

    https://msdn.microsoft.com/en-us/library/windows/desktop/hh848036(v=vs.85).aspx https://msdn.microso ...

  7. C# WinForm Judge Win7 Whether to run as an administrator

    original text :C# WinForm Judge Win7 Whether to run as an administrator If the program is not running as an administrator , Operating local files will prompt :System.UnauthorizedAccessException abnormal Vista and ...

  8. win7 Let the program run as administrator by default

    stay win7 Read with your own program in MBR when , It suddenly prompts that the disk cannot be operated , And in the xp I don't have this problem : Finally, right click to run as administrator to run normally . So I tried to make the program run as administrator by default when I double-click it to start . The specific methods : 1 ...

  9. 【VS Development 】win7 Let the program run as administrator by default

    stay win7 Read with your own program in MBR when , It suddenly prompts that the disk cannot be operated , And in the xp I don't have this problem : Finally, right click to run as administrator to run normally . So I tried to make the program run as administrator by default when I double-click it to start . The specific methods : 1 ...

Random recommendation

  1. Python From breaking in to rushing out

    MD Version network disk backup : link : https://pan.baidu.com/s/1kVJNRSz password : agxt be based on < concise Python course > One .Python overview 1. Use PyCharm Right and wrong ...

  2. JSP The second small case of login and registration ( No verification code , The front end intercepts the air parameter )

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...

  3. objective-c Bottom : runtime Mechanism

    runtime yes oc The true face of .oc The bottom set c Language API. unsigned int count; // Get the list of properties objc_property_t *propertyList = class_cop ...

  4. POJ 1741 The dots on the tree divide

    The main idea of the topic : Find that the distance between pairs of points on the tree is not greater than K The logarithm of the points This is a simple exercise point divide and conquer problem , What we should pay attention to is to prevent the appearance of point divide and conquer, and finally divide and conquer a subtree into a straight line , So use recursive method to find the most suitable root spot #include &l ...

  5. spring Declarative transaction internal diagram of

  6. MSMQ( Message queue )

    Some time ago, I studied WCF Access to MSMQ, So I studied it seriously , Here are my notes . I understand. MSMQ MSMQ It can be seen as a data storage device , It's like a database , It's just that the data store records one by one , and MSMQ What is stored is a ...

  7. Android: Control layout ( Single frame layout )FrameLayout

    FrameLayout: All controls are in the upper left corner , And directly cover the previous sub elements . Add... To the top layer shown : android:clickable="true" You can avoid clicking on the upper layer to trigger the lower layer . example : ...

  8. Python The actual combat int Study notes and simple exercises

    ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__ ...

  9. VK Cup 2017 - Квалификация 1

    CF Upper VK Cup 2017 Qualification Heat 1, It's like water , Because there is only Russian, language is the biggest obstacle -- But after that, it seems that there will be English .( It seems that the competition can only be seen in Russian mode --) Duration 1 God , No point deduction over time .FallDream ...

  10. BZOJ_2303_[Apio2011] Checkerboard dyeing _ Union checking set

    BZOJ_2303_[Apio2011] Checkerboard dyeing _ Union checking set Description Sam And his sister Sara There is a n × m It's a square form . They want to dye each of their squares red or blue . Out of personal preference , ...