-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJava-Update.ps1
2268 lines (1735 loc) · 121 KB
/
Java-Update.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
Java-Update.ps1
Please Note:
- It's assumed that a 64-bit Java is going to be used in a 64-bit machine.
- It's assumed that only one (the most recent non-beta available) version of Java is intended to be used.
- If enough rights are deemed to be possessed (PowerShell has been started with the 'run as an administrator' option), any not up-to-date versions of Java will be uninstalled, and successively if the most recent non-beta version of Java is not found on the system, one instance will be installed (the 64-bit Java to a 64-bit machine and the 32-bit Java to a 32-bit machine).
- So if, for example, 32-bit and 64-bit outdated Java is installed in a 64-bit machine, only the most recent 64-bit Java replaces those versions. For more granular uninstallation/installation procedures, please consider doing the uninstallation manually via the Control Panel or by using the Java Uninstall Tool (please see the Step 19 for futher details about the Java Uninstall Tool) and downloading the relevant files manually (for download URLs, please see the Step 16 below) or changing this script according to the prevailing preferences.
- System Files are altered, for instance, in Steps 4, 5, 19 and 24.
- Please consider reviewing at least the Steps 4 and 5, since eventually (after some update iterations) the written settings will also be used in the Java installations not initiated by this script.
- Processes may be stopped in Step 6 and will be stopped in Step 18 without any further notification to the end-user or without any question prompts presented beforehand.
#>
$path = $env:temp
$computer = $env:COMPUTERNAME
$ErrorActionPreference = "Stop"
$start_time = Get-Date
$empty_line = ""
$quote ='"'
$unquote ='"'
$original_javases = @()
$duplicate_uninstall = @()
$java_enumeration = @()
$uninstalled_old_javas = @()
$new_javases = @()
# C:\Windows\system32\msiexec.exe
$path_system_32 = [Environment]::GetFolderPath("System")
$msiexec = "$path_system_32\msiexec.exe"
# C:\Windows\system32\cmd.exe
$cmd = "$path_system_32\cmd.exe"
# General Java URLs:
# Source: https://bugs.openjdk.java.net/browse/JDK-8005362
$uninstaller_tool_url = "https://javadl-esd-secure.oracle.com/update/jut/JavaUninstallTool.exe"
$uninstaller_info_url = "https://www.java.com/en/download/help/uninstall_java.xml"
$release_history_url = "https://www.java.com/en/download/faq/release_dates.xml"
$baseline_url = "https://javadl-esd-secure.oracle.com/update/baseline.version"
# 32-bit Java ID Numbers (JRE 4 -)
# Source: http://pastebin.com/73JqpTqv
# Source: https://github.com/bmrf/standalone_scripts/blob/master/java_runtime_nuker.bat
# Source: http://www.itninja.com/question/silent-uninstall-java-all-versions
$regex_32_a = "{26A24AE4-039D-4CA4-87B4-2F32(\d+)..}"
$regex_32_b = "{26A24AE4-039D-4CA4-87B4-2F.32(\d+)..}"
$regex_32_c = "{3248F0A8-6813-11D6-A77B-00B0D0(\d+).}"
$regex_32_d = "{7148F0A8-6813-11D6-A77B-00B0D0(\d+).}"
# 64-bit Java ID Numbers (Java 6 Update 23 -)
# Source: http://pastebin.com/73JqpTqv
# Source: https://github.com/bmrf/standalone_scripts/blob/master/java_runtime_nuker.bat
# Source: http://www.itninja.com/question/silent-uninstall-java-all-versions
$regex_64_a = "{26A24AE4-039D-4CA4-87B4-2F64(\d+)..}"
$regex_64_b = "{26A24AE4-039D-4CA4-87B4-2F.64(\d+)..}"
# Step 1
# Determine the architecture of a machine # Credit: Tobias Weltner: "PowerTips Monthly vol 8 January 2014"
If ([IntPtr]::Size -eq 8) {
$empty_line | Out-String
"Running in a 64-bit subsystem" | Out-String
$64 = $true
$bit_number = "64"
$registry_paths = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
$empty_line | Out-String
} Else {
$empty_line | Out-String
"Running in a 32-bit subsystem" | Out-String
$64 = $false
$bit_number = "32"
$registry_paths = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
$empty_line | Out-String
} # Else
# Determine if the script is run in an elevated window # Credit: alejandro5042: "How to run exe with/without elevated privileges from PowerShell"
$is_elevated = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
# Function to check whether a program is installed or not
Function Check-InstalledSoftware ($display_name) {
Return Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -eq $display_name }
} # function
# Function to check whether a certain version of Java is installed or not
Function Check-JavaID ($id_number) {
Return Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match $id_number }
} # function
# Step 2
# Find out the which kind of Java is installed
$java_is_installed = $false
$32_bit_java_is_installed = $false
$64_bit_java_is_installed = $false
$auto_updater_is_installed = $false
$existing_javas = Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue | Where-Object { ($_.DisplayName -like "*Java*" -or $_.DisplayName -like "*J2SE Runtime*") -and ($_.Publisher -like "Oracle*" -or $_.Publisher -like "Sun*" )}
# $query= "select * from win32_Product where (Name like 'Java %' or Name like 'Java(TM)%' or Name like 'J2SE%') and (Name <> 'Java Auto Updater') and ((Vendor='Sun Microsystems, Inc.') or (Vendor='Oracle') or (Vendor='Oracle Corporation')) and (NOT Name like '%CompuGROUP%') and (NOT Name like '%IBM%') and (NOT Name like '%DB%') and (NOT Name like '%Advanced Imaging%') and (NOT Name like '%Media Framework%') and (NOT Name like '%SDK%') and (NOT Name like '%Development Kit%')"
# https://poshuninstalljava.codeplex.com/SourceControl/latest#uninstall-java.ps1
# Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue | Where-Object { ($_.DisplayName -like "*Java*" -or $_.DisplayName -like "*J2SE Runtime*") -and ($_.Publisher -like "Oracle*" -or $_.Publisher -like "Sun*") -and (-not $_.DisplayName -like "*SDK*") -and (-not $_.DisplayName -like "*Development Kit*") }
# Number of Installed Javas
If ($existing_javas -eq $null) {
$number_of_installed_javas = 0
} Else {
$number_of_installed_javas = ($existing_javas | Measure-Object).Count
} # Else
# Installed Java Types
If ($existing_javas -ne $null) {
$java_is_installed = $true
ForEach ($original_java in $existing_javas) {
# Custom Uninstall Strings
$original_arguments = "/uninstall $($original_java.PSChildName) /qn /norestart"
$original_uninstall_string = "$msiexec /uninstall $($original_java.PSChildName) /qn"
$original_powershell_uninstall_string = [string]"Start-Process -FilePath $msiexec -ArgumentList " + $quote + $original_arguments + $unquote + " -Wait"
$original_product_version = ((Get-ItemProperty -Path "$($original_java.InstallLocation)\bin\java.exe" -ErrorAction SilentlyContinue -Name VersionInfo).VersionInfo).ProductVersion
$regex_build = If ($original_product_version -ne $null) { $original_product_version -match "(?<P1>\d+)\.(?<P2>\d+)\.(?<P3>\d+)\.(?<P4>\d+)" } Else { $continue = $true }
$original_javases += $obj_java = New-Object -TypeName PSCustomObject -Property @{
'Name' = $original_java.DisplayName.replace("(TM)","")
'Version' = $original_java.DisplayVersion
'Major_Version' = [int32]$original_java.VersionMajor
'Build_Number' = If ($Matches.P4 -ne $null) { [string]"b" + $Matches.P4 } Else { $continue = $true }
'Install_Date' = $original_java.InstallDate
'Install_Location' = $original_java.InstallLocation
'Publisher' = $original_java.Publisher
'Computer' = $computer
'ID' = $original_java.PSChildName
'Standard_Uninstall_String' = $original_java.UninstallString
'Custom_Uninstall_String' = $original_uninstall_string
'PowerShell_Uninstall_String' = $original_powershell_uninstall_string
'Type' = If (($original_java.PSChildName -match $regex_32_a) -or ($original_java.PSChildName -match $regex_32_b) -or ($original_java.PSChildName -match $regex_32_c) -or ($original_java.PSChildName -match $regex_32_d)) {
"32-bit"
} ElseIf (($original_java.PSChildName -match $regex_64_a) -or ($original_java.PSChildName -match $regex_64_b)) {
"64-bit"
} Else {
$continue = $true
} # Else
'Update_Number' = If (($original_java.PSChildName -match $regex_32_a) -or ($original_java.PSChildName -match $regex_32_b) -or ($original_java.PSChildName -match $regex_32_c) -or ($original_java.PSChildName -match $regex_32_d)) {
[int32]$original_java.DisplayName.Split()[-1]
} ElseIf (($original_java.PSChildName -match $regex_64_a) -or ($original_java.PSChildName -match $regex_64_b)) {
[int32]$original_java.DisplayName.Split()[-2]
} Else {
$continue = $true
} # Else
} # New-Object
} # ForEach ($original_java)
$original_javases.PSObject.TypeNames.Insert(0,"Original Installed Java Versions")
} Else {
$continue = $true
} # Else
# 32-bit Java
If ((Check-JavaID $regex_32_a -ne $null) -or (Check-JavaID $regex_32_b -ne $null) -or (Check-JavaID $regex_32_c -ne $null) -or (Check-JavaID $regex_32_d -ne $null)) {
$32_bit_java_is_installed = $true
$original_java_32_bit_powershell_uninstall_string = $original_javases | Where-Object { $_.Type -eq "32-bit" } | Select-Object -ExpandProperty PowerShell_Uninstall_String
} Else {
$continue = $true
} # Else
# 64-bit Java
If ((Check-JavaID $regex_64_a -ne $null) -or (Check-JavaID $regex_64_b -ne $null)) {
$64_bit_java_is_installed = $true
$original_java_64_bit_powershell_uninstall_string = $original_javases | Where-Object { $_.Type -eq "64-bit" } | Select-Object -ExpandProperty PowerShell_Uninstall_String
} Else {
$continue = $true
} # Else
# Installed Version(s)
$installed_java_version_text_format = ($original_javases | Select-Object -ExpandProperty Name)
# Installed Java Version Number(s)
$installed_java_version = $original_javases | Where-Object { $_.Name -ne "Java Auto Updater" } | Select-Object -ExpandProperty Version
# Installed Java Main Version(s)
$installed_java_major_version = $original_javases | Where-Object { $_.Name -ne "Java Auto Updater" } | Select-Object -ExpandProperty Major_Version
# Installed Java Update Number(s)
$installed_java_update_number = $original_javases | Where-Object { $_.Name -ne "Java Auto Updater" } | Select-Object -ExpandProperty Update_Number
# Installed Build Number(s)
$installed_java_build_number = $original_javases | Where-Object { $_.Name -ne "Java Auto Updater" } | Select-Object -ExpandProperty Build_Number
# Java Installation Path(s)
$java_home_path = $original_javases | Where-Object { $_.Name -ne "Java Auto Updater" } | Select-Object -ExpandProperty Install_Location
# Java Auto Updater Is Installed?
If (Check-InstalledSoftware "Java Auto Updater") { $auto_updater_is_installed = $true } Else { $continue = $true }
If (($auto_updater_is_installed -eq $true) -and ($number_of_installed_javas -eq 1)) {
# Only the Java Auto Updater is installed
$exception_one = $true
} Else {
$continue = $true
} # Else
# Step 3
# Gather more details about the latest installed version of Java
$java_reg_path = 'HKLM:\Software\JavaSoft\Java Runtime Environment'
If ((Test-Path $java_reg_path) -eq $true) {
# $java_8_is_installed = $true
$existing_installed_version = (Get-ItemProperty -Path $java_reg_path -Name CurrentVersion).CurrentVersion
# Java Installation Path
$java_home_path_reg = (Get-ItemProperty -Path "$java_reg_path\$existing_installed_version" -Name JavaHome).JavaHome
# Installed Java Description:
$installed_java_description = ((Get-ChildItem "$java_home_path_reg\bin\java.exe").VersionInfo.ProductName).Replace("(TM)","")
# Installed Java Version (legacy_format):
# 8.0.1110.14
$installed_java_version_alternative_legacy_format = (Get-ChildItem "$java_home_path_reg\bin\java.exe").VersionInfo.ProductVersion
# Latest installed Java Main Version:
$latest_installed_java_major_version = [int32](Get-ChildItem "$java_home_path_reg\bin\java.exe").VersionInfo.ProductMajorPart
# Installed Java Update Number (legacy_format):
# 1110
$installed_java_alternative_legacy_update_number = [int32](Get-ChildItem "$java_home_path_reg\bin\java.exe").VersionInfo.ProductBuildPart
} Else {
$continue = $true
} # Else (Step 3)
# Step 4
# Set the Java deployment properties and with an alternative method find out the build number
# Note: Please consider reviewing these settings, since eventually (after some update iterations) these will also be used in the Java installations not initiated by this script.
# Source: http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/properties.html
<#
The following locations provide examples for each operating system:
Windows 7:
For user jsmith running on Windows 7, the deployment.properties file would be located in the following directory:
C:\Users\jsmith\AppData\LocalLow\Sun\Java\Deployment\deployment.properties
<User Application Data Folder>\LocalLow\Sun\Java\Deployment\deployment.properties
Linux:
For user bjones running on Solaris or Linux, the deployment.properties file would be located in the following directory:
/home/bjones/.java/deployment/deployment.properties
${user.home}/.java/deployment/deployment.properties
OS X:
For user jdoe running on OS X, the deployment.properties file would be located in the following directory:
/Users/jdoe/Library/Application Support/Oracle/Java/Deployment/deployment.properties
~/Library/Application Support/Oracle/Java/Deployment/deployment.properties
#>
If ((Test-Path $java_reg_path) -eq $true) {
# Step 4.1
# "deployment.properties" File Location # 1/2 (Store user settings in the roaming profile = false)
$appdata_path = [string][Environment]::GetFolderPath("LocalApplicationData") + 'Low\Sun\Java\Deployment'
If ((Test-Path $appdata_path\deployment.properties) -eq $true) {
$app_path = $appdata_path
If ((Test-Path $appdata_path\deployment.properties_original) -eq $true) {
# If the "original" version of the deployment.properties file exists, do not overwrite it, but instead create another backup that gets overwritten each time this script is run this deep
copy $appdata_path\deployment.properties $appdata_path\deployment.properties.old
} Else {
# If an "original" version of this file does not exist, create it (practically when this script is run for the first time)
copy $appdata_path\deployment.properties $appdata_path\deployment.properties_original
} # Else
# Get-Content $appdata_path\deployment.properties
$seed_file = "$appdata_path\deployment.properties"
$destination_file = "$appdata_path\deployment.properties.new"
$new_configuration_file = New-Item -ItemType File -Path "$destination_file" -Force
# Installed Java Version (Almost Full, with an underscore: x.y.z_nnn) - Legacy Format:
# 1.8.0_101
$installed_java_version_reg = ((Get-Content $seed_file | Select-String 'deployment.javaws.jre.0.product=') -split '=')[1]
# Installed Java Version (x.y.z) - Old Name:
$installed_baseline = $installed_java_version_reg.split("_")[0]
# Installed Java Update Number (nnn):
$installed_update_number_reg = [int32]$installed_java_version_reg.split("_")[1]
# Security Tab
# Disable Java content in the browser
If ((Get-Content $seed_file | Select-String 'deployment.webjava.enabled') -eq $null) {
# The 'display Java content in the browser' setting is missing = $true
$new_configuration_file
Add-Content $new_configuration_file -Value (Get-Content $seed_file)
Add-Content $new_configuration_file -Value 'deployment.webjava.enabled=false'
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
If ((Get-Content $seed_file | Select-String 'deployment.webjava.enabled=true') -eq $true) {
# Java content is enabled in the browser = $true
(Get-Content $seed_file) | Foreach-Object { $_ -replace 'deployment.webjava.enabled=true', 'deployment.webjava.enabled=false' } | Set-Content $destination_file
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
# Advanced Tab
# Disable Third Party Advertisements
If ((Get-Content $seed_file | Select-String 'install.disable.sponsor.offers') -eq $null) {
# The 'Third Party Advertisement' setting is missing = $true
$new_configuration_file
Add-Content $new_configuration_file -Value (Get-Content $seed_file)
Add-Content $new_configuration_file -Value 'install.disable.sponsor.offers=true'
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
If ((Get-Content $seed_file | Select-String 'install.disable.sponsor.offers=false') -eq $true) {
# The Third Party Advertisements are enabled = $true
(Get-Content $seed_file) | Foreach-Object { $_ -replace 'install.disable.sponsor.offers=false', 'install.disable.sponsor.offers=true' } | Set-Content $destination_file
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
} # if (Step 4.1)
# Step 4.2
# "deployment.properties" File Location # 2/2 (Store user settings in the roaming profile = true)
$alternative_appdata_path = [string][Environment]::GetFolderPath("ApplicationData") + '\Sun\Java\Deployment'
If ((Test-Path $alternative_appdata_path\deployment.properties) -eq $true) {
$app_path = $alternative_appdata_path
If ((Test-Path $alternative_appdata_path\deployment.properties_original) -eq $true) {
# If the "original" version of the deployment.properties file exists, do not overwrite it, but instead create another backup that gets overwritten each time this script is run this deep
copy $alternative_appdata_path\deployment.properties $alternative_appdata_path\deployment.properties.old
} Else {
# If an "original" version of this file does not exist, create it (practically when this script is run for the first time)
copy $alternative_appdata_path\deployment.properties $alternative_appdata_path\deployment.properties_original
} # Else
# Get-Content $alternative_appdata_path\deployment.properties
$seed_file = "$alternative_appdata_path\deployment.properties"
$destination_file = "$alternative_appdata_path\deployment.properties.new"
$new_configuration_file = New-Item -ItemType File -Path "$destination_file" -Force
# Installed Java Version (Almost Full, with an underscore: x.y.z_nnn) - Legacy Format:
# 1.8.0_101
$installed_java_version_reg = ((Get-Content $seed_file | Select-String 'deployment.javaws.jre.0.product=') -split '=')[1]
# Installed Java Version (x.y.z) - Old Name:
$installed_baseline = $installed_java_version_reg.split("_")[0]
# Installed Java Update Number (nnn):
$installed_update_number_reg = [int32]$installed_java_version_reg.split("_")[1]
# Security Tab
# Disable Java content in the browser
If ((Get-Content $seed_file | Select-String 'deployment.webjava.enabled') -eq $null) {
# The 'display Java content in the browser' setting is missing = $true
$new_configuration_file
Add-Content $new_configuration_file -Value (Get-Content $seed_file)
Add-Content $new_configuration_file -Value 'deployment.webjava.enabled=false'
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
If ((Get-Content $seed_file | Select-String 'deployment.webjava.enabled=true') -eq $true) {
# Java content is enabled in the browser = $true
(Get-Content $seed_file) | Foreach-Object { $_ -replace 'deployment.webjava.enabled=true', 'deployment.webjava.enabled=false' } | Set-Content $destination_file
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
# Advanced Tab
# Disable Third Party Advertisements
If ((Get-Content $seed_file | Select-String 'install.disable.sponsor.offers') -eq $null) {
# The 'Third Party Advertisement' setting is missing = $true
$new_configuration_file
Add-Content $new_configuration_file -Value (Get-Content $seed_file)
Add-Content $new_configuration_file -Value 'install.disable.sponsor.offers=true'
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
If ((Get-Content $seed_file | Select-String 'install.disable.sponsor.offers=false') -eq $true) {
# The Third Party Advertisements are enabled = $true
(Get-Content $seed_file) | Foreach-Object { $_ -replace 'install.disable.sponsor.offers=false', 'install.disable.sponsor.offers=true' } | Set-Content $destination_file
copy $destination_file $seed_file
} Else {
$continue = $true
} # Else
} # if (Step 4.2)
# Installed Java Build Name
If ((Test-Path $java_reg_path\$installed_java_version_reg\MSI) -eq $true) {
$installed_java_build_name_reg = (Get-ItemProperty -Path "$java_reg_path\$installed_java_version_reg\MSI" -Name FullVersion).FullVersion
} Else {
$continue = $true
} # Else
} Else {
$continue = $true
} # Else (Step 4)
$obj_installed += New-Object -TypeName PSCustomObject -Property @{
'Installed Version' = $installed_java_version_text_format
'Installed Java Main Version' = $installed_java_major_version
'Installed Java Update Number' = $installed_java_update_number
'Installed Version (Legacy Name)' = $installed_java_version
'Installed Java Build' = $installed_java_build_number
'Description' = $installed_java_description
'Java Installation Path' = $java_home_path
'Configuration File Location' = $app_path
'java_config.txt File Location' = $path
'Java Release History' = $release_history_url
'Java Uninstallation Info' = $uninstaller_info_url
'Java Uninstall Tool URL' = $uninstaller_tool_url
'Java Is Installed?' = $java_is_installed
'How Many Instances of Java is Found?' = $number_of_installed_javas
'Java Auto Updater Is Installed?' = $auto_updater_is_installed
'32-bit Java Is Installed?' = $32_bit_java_is_installed
'64-bit Java Is Installed?' = $64_bit_java_is_installed
} # New-Object
$obj_installed.PSObject.TypeNames.Insert(0,"Installed Java Versions")
$obj_installed_selection = $obj_installed | Select-Object 'Installed Version','Installed Java Main Version','Installed Java Update Number','Installed Java Build','Installed Version (Legacy Name)','Description','Java Installation Path','Configuration File Location','java_config.txt File Location','Java Release History','Java Uninstallation Info','Java Uninstall Tool URL','Java Is Installed?','How Many Instances of Java is Found?','Java Auto Updater Is Installed?','32-bit Java Is Installed?','64-bit Java Is Installed?'
# Display the Installed Java version numbers in console
$empty_line | Out-String
$header_installed = "Existing (Installed) Java Versions' Summary Table"
$coline_installed = "-------------------------------------------------"
Write-Output $header_installed
$coline_installed | Out-String
Write-Output $obj_installed_selection
# Step 5
# Create a Java Install Configuration File
# Note: Please see the steps 4.1 and 4.2 above for Java deployment properties (the "deployment.properties" -file)
# Note: Please consider reviewing these settings, since eventually (after some update iterations) these will also be used in the Java installations not initiated by this script.
# Source: http://docs.oracle.com/javase/8/docs/technotes/guides/install/config.html#installing_with_config_file
# Source: http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.html
# Source: http://docs.oracle.com/javacomponents/msi-jre8/install-guide/installing_jre_msi.htm#msi_install_command_line
# Source: http://stackoverflow.com/questions/28043588/installing-jdk-8-and-jre-8-silently-on-a-windows-machine-through-command-line
<#
jre [INSTALLCFG=configuration_file_path] [options]
jre INSTALLCFG=configuration_file_path
jre is the installer base file name, for example, jre-8u05-windows-i586.exe. jre refers to the JRE Windows Offline Installer base file name
configuration_file_path is the path to the configuration file. Specifies the path of the installer configuration file.
options are options with specified values separated by spaces. Use the same options as listed in Table 20-1, "Configuration File Options". In addition, you may use the option /s for the JRE Windows Offline Installer to perform a silent installation. You may substitute the value Enable for 1 and the value Disable for 0.
# Silent install removing old Java and creating a logfile example:
jre1.8.0_60.exe /s /L C:\pathsetup.log REMOVEOUTOFDATEJRES=1
# Using a configuration file and creating a logfile example:
jre-8u31-windows-x64.exe INSTALLCFG="%ProgramData%\Java8Configuration\Java8u31config.txt" /L C:\Temp\Java8u31x64itRuntime_install.log
jre-8-windows-i586.exe INSTALLCFG=jre-install-options.txt /s /L C:\TMP\jre-install.log
# cmd.exe Command Prompt with Administrative rights
msiexec.exe /i jre1.8.0_31_64bit.msi /L*v C:\Temp\Java8u31x64it_verb_Runtime_install.log INSTALL_SILENT="Enable" AUTO_UPDATE="Disable" WEB_JAVA="Enable" WEB_ANALYTICS="Disable" EULA="Disable" NOSTARTMENU="Enable" /qb
msiexec.exe /i %~dp0jre-8u45-windows-i586.msi INSTALLCFG=%~dp0custom.cfg /qn /L c:\log\jre-8u45-windows-i586.log
# Basic UI mode:
msiexec.exe /i installer.msi [INSTALLCFG=configuration_file_path] [options] /qb
# Silent or unattended mode:
msiexec.exe /i installer.msi [INSTALLCFG=configuration_file_path] [options] /qn
#>
$java_config = New-Item -ItemType File -Path "$path\java_config.txt" -Force
$java_config
Add-Content $java_config -Value ('INSTALL_SILENT=1
AUTO_UPDATE=0
WEB_JAVA=0
WEB_JAVA_SECURITY_LEVEL=VH
WEB_ANALYTICS=0
EULA=0
REBOOT=0
REBOOT=Suppress
REBOOT=ReallySuppress
NOSTARTMENU=1
SPONSORS=0
REMOVEOUTOFDATEJRES=1')
# Step 6
# If more than one instance of Java is installed on the system, notify the user, and try to remove the excessive Java(s), if enough permissions are deemed to be available
If ((($number_of_installed_javas -eq 1) -and ($auto_updater_is_installed -eq $false)) -or (($number_of_installed_javas -eq 2) -and ($32_bit_java_is_installed -eq $true) -and ($64_bit_java_is_installed -eq $true) -and ($auto_updater_is_installed -eq $false))) {
$excessive_javas_are_installed = $false
$continue = $true
} ElseIf (($number_of_installed_javas -gt 1 ) -or ($auto_updater_is_installed -eq $true)) {
$excessive_javas_are_installed = $true
$empty_line | Out-String
If ($number_of_installed_javas -gt 1) {
Write-Warning "More than one instance of Java seems to be installed on the system."
} ElseIf ($auto_updater_is_installed -eq $true) {
Write-Warning "Java Auto Updater seems to be installed on the system."
} Else {
$continue = $true
} # Else
# Check if the PowerShell session is elevated (has been run as an administrator) and try to remove the duplicate Java if enough permissions are deemed to be available
If ($is_elevated -eq $true) {
# Stop the Java-related processes
Stop-Process -ProcessName '*messenger*' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'FlashPlayer*' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'plugin-container*' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'chrome*' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'opera*' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'firefox' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'palemoon' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'iexplore' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName 'iexplorer' -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName java -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName javaw -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName javaws -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName JP2Launcher -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName jqs -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName jucheck -ErrorAction SilentlyContinue -Force
Stop-Process -ProcessName jusched -ErrorAction SilentlyContinue -Force
Start-Sleep -s 2
# The Duplicate Java Uninstallation Protocol
# If ($installed_java_version_alternative_legacy_format -ne $null) {
If ($original_javases -ne $null) {
$timestamp_multi = Get-Date -Format HH:mm:ss
$multi_text_1 = "$timestamp_multi - Initiating the Duplicate Java Uninstallation Protocol..."
$multi_text_2 = "Trying to keep the latest installed version of Java (in both 32-bit and 64-bit flavors) and removing the earlier Java version (including the Java Auto Updater)."
$multi_text_3 = "Trying to keep the latest installed version of Java (in both 32-bit and 64-bit flavors) and removing the earlier Java versions (including the Java Auto Updater)."
$empty_line | Out-String
Write-Output $multi_text_1
$empty_line | Out-String
If ($number_of_installed_javas -eq 2) {
Write-Output $multi_text_2
} Else {
Write-Output $multi_text_3
} # Else
# Uninstall the Java Auto Updater
$the_java_auto_updater_exists = Check-InstalledSoftware "Java Auto Updater"
If ($the_java_auto_updater_exists) {
$argument_the_java_auto_updater = "/uninstall $($the_java_auto_updater_exists.PSChildName) /qn /norestart"
Start-Process -FilePath $msiexec -ArgumentList "$argument_the_java_auto_updater" -Wait
Start-Process -FilePath $msiexec -ArgumentList "/uninstall {4A03706F-666A-4037-7777-5F2748764D10} /qn /norestart" -Wait
If ((Check-InstalledSoftware "Java Auto Updater").DisplayName -eq $null) {
$the_uninstall_text = "$($the_java_auto_updater_exists.DisplayName) is uninstalled."
$empty_line | Out-String
Write-Output $the_uninstall_text
} Else {
$continue = $true
} # Else If (Check-InstalledSoftware)
} Else {
$continue = $true
} # Else If ($the_java_auto_updater_exists)
# Find out the most recent Java out of all the installed Javas
$highest_java_main_version = $original_javases | Select-Object -ExpandProperty Major_Version | Sort-Object -Descending | Select-Object -First 1
$highest_java_update_number = $original_javases | Where-Object Major_Version -eq $highest_java_main_version | Select-Object -ExpandProperty Update_Number | Sort-Object -Descending | Select-Object -First 1
$highest_java_version = $original_javases | Where-Object Major_Version -eq $highest_java_main_version | Where-Object Update_Number -eq $highest_java_update_number | Select-Object -ExpandProperty Version
ForEach ($java in $original_javases) {
If ($java.Version -ne $highest_java_version) {
# Uninstall any remaining duplicate and old instances of Java
# 8.0.1110.14
# Source: http://docs.oracle.com/javacomponents/msi-jre8/install-guide/installing_jre_msi.htm#msi_system_requirements
<#
Uninstalling the JRE with the Command Line
32-bit JRE: msiexec /x {26A24AE4-039D-4CA4-87B4-2F83218025F0}
64-bit JRE: msiexec /x {26A24AE4-039D-4CA4-87B4-2F86418025F0}
The value in curly braces is the MSI product code for the JRE about to be uninstalled. The latter part, 18025, correlates to the JRE version 1.8.0_25.
#>
Start-Sleep -s 2
Write-Verbose "$($java.Name) version $($java.Version) installed on $($java.Install_Date) is uninstalling..."
$duplicate_uninstall += $obj_uninstall = New-Object -TypeName PSCustomObject -Property @{
'Computer' = $computer
'Name' = $java.Name
'Version' = $java.Version
'IdentifyingNumber' = $java.ID
'InstallDate' = $java.Install_Date
'InstallLocation' = $java.Install_Location
} # New-Object
$duplicate_uninstall.PSObject.TypeNames.Insert(0,"Uninstalled Old Duplicate Java Versions")
$argument_java_uninstall = "/uninstall $($java.ID) /qn /norestart"
Start-Process -FilePath $msiexec -ArgumentList "$argument_java_uninstall" -Wait
$uninstall_text = "$($java.Name) is uninstalled."
$empty_line | Out-String
Write-Output $uninstall_text
} Else {
# This instance "slot" is altering the the latest installed Java version
# Do not touch the latest installed Java version = $true
$continue = $true
} # Else
} # ForEach ($java)
$timestamp_protocol = Get-Date -Format HH:mm:ss
$protocol_text = "$timestamp_protocol - The Duplicate Java Uninstallation Protocol completed."
$empty_line | Out-String
Write-Output $protocol_text
} Else {
$continue = $true
} # Else (The Duplicate Java Uninstallation Protocol)
# Check the Status of Java after The Duplicate Java Uninstallation Protocol
$java_is_installed = $false
$32_bit_java_is_installed = $false
$64_bit_java_is_installed = $false
$auto_updater_is_installed = $false
$reduced_javas = Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue | Where-Object { ($_.DisplayName -like "*Java*" -or $_.DisplayName -like "*J2SE Runtime*") -and ($_.Publisher -like "Oracle*" -or $_.Publisher -like "Sun*" )}
# Number of Installed Javas
If ($reduced_javas -eq $null) {
$number_of_installed_javas = 0
} Else {
$number_of_installed_javas = ($reduced_javas | Measure-Object).Count
} # Else
# Is Java Installed?
If ($reduced_javas -ne $null) {
$java_is_installed = $true
} Else {
$continue = $true
} # Else
# 32-bit Java
If ((Check-JavaID $regex_32_a -ne $null) -or (Check-JavaID $regex_32_b -ne $null) -or (Check-JavaID $regex_32_c -ne $null) -or (Check-JavaID $regex_32_d -ne $null)) {
$32_bit_java_is_installed = $true
} Else {
$continue = $true
} # Else
# 64-bit Java
If ((Check-JavaID $regex_64_a -ne $null) -or (Check-JavaID $regex_64_b -ne $null)) {
$64_bit_java_is_installed = $true
} Else {
$continue = $true
} # Else
# Java Auto Updater
If (Check-InstalledSoftware "Java Auto Updater") { $auto_updater_is_installed = $true } Else { $continue = $true }
} Else {
$continue = $true
} # Else (If "Administrator" -eq $true)
} Else {
$continue = $true
} # Else (Step 6)
# Step 7
# Enumerate the existing installed Javas
$registry_paths_selection = Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue | Where-Object { ($_.DisplayName -like "*Java*" -or $_.DisplayName -like "*J2SE Runtime*") -and ($_.Publisher -like "Oracle*" -or $_.Publisher -like "Sun*" )}
If ($registry_paths_selection -ne $null) {
ForEach ($item in $registry_paths_selection) {
# Custom Uninstall Strings
$arguments = "/uninstall $($item.PSChildName) /qn /norestart"
$custom_uninstall_string = "$msiexec /uninstall $($item.PSChildName) /qn"
$powershell_uninstall_string = [string]"Start-Process -FilePath $msiexec -ArgumentList " + $quote + $arguments + $unquote + " -Wait"
$product_version_enum = ((Get-ItemProperty -Path "$($item.InstallLocation)\bin\java.exe" -ErrorAction SilentlyContinue -Name VersionInfo).VersionInfo).ProductVersion
$regex_build_enumeration = If ($product_version_enum -ne $null) { $product_version_enum -match "(?<C1>\d+)\.(?<C2>\d+)\.(?<C3>\d+)\.(?<C4>\d+)" } Else { $continue = $true }
$java_enumeration += $obj_enumeration = New-Object -TypeName PSCustomObject -Property @{
'Name' = $item.DisplayName.replace("(TM)","")
'Version' = $item.DisplayVersion
'Main Version' = [int32]$item.VersionMajor
'Build' = If ($Matches.C4 -ne $null) { [string]"b" + $Matches.C4 } Else { $continue = $true }
'Install Date' = $item.InstallDate
'Install Location' = $item.InstallLocation
'Publisher' = $item.Publisher
'Computer' = $computer
'Identifying Number' = $item.PSChildName
'Standard Uninstall String' = $item.UninstallString
'Custom Uninstall String' = $custom_uninstall_string
'PowerShell Uninstall String' = $powershell_uninstall_string
'Type' = If (($item.PSChildName -match $regex_32_a) -or ($item.PSChildName -match $regex_32_b) -or ($item.PSChildName -match $regex_32_c) -or ($item.PSChildName -match $regex_32_d)) {
"32-bit"
} ElseIf (($item.PSChildName -match $regex_64_a) -or ($item.PSChildName -match $regex_64_b)) {
"64-bit"
} Else {
$continue = $true
} # Else
'Update Number' = If (($item.PSChildName -match $regex_32_a) -or ($item.PSChildName -match $regex_32_b) -or ($item.PSChildName -match $regex_32_c) -or ($item.PSChildName -match $regex_32_d)) {
[int32]$item.DisplayName.Split()[-1]
} ElseIf (($item.PSChildName -match $regex_64_a) -or ($item.PSChildName -match $regex_64_b)) {
[int32]$item.DisplayName.Split()[-2]
} Else {
$continue = $true
} # Else
} # New-Object
} # ForEach ($item)
# Display the Java Version Enumeration in console
If ($java_enumeration -ne $null) {
$java_enumeration.PSObject.TypeNames.Insert(0,"Java Version Enumeration")
$java_enumeration_selection = $java_enumeration | Select-Object 'Name','Main Version','Update Number','Build','Version','Install Date','Type','Install Location','Publisher','Computer','Identifying Number','PowerShell Uninstall String'
$empty_line | Out-String
$header_java_enumeration = "Enumeration of Java Versions Found on the System"
$coline_java_enumeration = "------------------------------------------------"
Write-Output $header_java_enumeration
$coline_java_enumeration | Out-String
Write-Output $java_enumeration_selection
} Else {
$continue = $true
} # Else
} Else {
$continue = $true
} # Else (Step 7)
# Step 8
# Check if the computer is connected to the Internet # Credit: ps1: "Test Internet connection"
If (([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet) -eq $false) {
$empty_line | Out-String
Return "The Internet connection doesn't seem to be working. Exiting without checking the latest Java version numbers or without updating Java (at Step 8)."
} Else {
Write-Verbose 'Checking the most recent Java version numbers from the Java/Oracle website...'
} # Else
# Step 9
# Check the baseline Java version number by connecting to the Java/Oracle website (Page 1) and write it to a file (The Baseline)
$baseline_file = "$path\java_baseline.csv"
try
{
$download_baseline = New-Object System.Net.WebClient
$download_baseline.DownloadFile($baseline_url, $baseline_file)
}
catch [System.Net.WebException]
{
Write-Warning "Failed to access $baseline_url"
If (([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet) -eq $true) {
$page_exception_text = "Please consider running this script again. Sometimes this Oracle page just isn't queryable for no apparent reason. The success rate 'in the second go' usually seems to be a bit higher."
$empty_line | Out-String
Write-Output $page_exception_text
} Else {
$continue = $true
} # Else
$empty_line | Out-String
Return "Exiting without checking the latest Java version numbers or without updating Java (at Step 9)."
}
Start-Sleep -Seconds 3
# Selects the second result from java_baseline.csv
# https://github.com/auberginehill/java-update/issues/1
$source = Get-Content $baseline_file | Select-Object -Skip 1 | Select-Object -First 1
$regex = $source -match "(?<P1>\d+).(?<P2>\d+).(?<P3>\d+)_(?<P4>\d+)"
# Most Recent Java Baseline Version (x.y.z) - Old Name:
$current_baseline = $source.split("_")[0]
# Most Recent Java Update Number (nnn):
# $current_update_number = $Matches.P4
$current_update_number = [int32]$source.split("_")[1]
# Most Recent Java Main Version (y):
$current_main_version = [int32]$Matches.P2
# Most Recent Java Version (Almost Full, with an underscore: x.y.z_nnn) - Legacy Format:
# 1.8.0_111
$current_version_full = $source
# Step 10
# Check the most recent Java version numbers by connecting to the Java/Oracle website (Page 2, The Java Update Chart / Map)
# Source: http://superuser.com/questions/443686/silent-java-update-check
# http://javadl-esd.sun.com/update/1.8.0/map-m-1.8.0.xml
# http://javadl-esd.sun.com/update/1.8.0/map-1.8.0.xml
$update_map_url = "http://javadl-esd.sun.com/update/$current_baseline/map-m-$current_baseline.xml"
try
{
$java_update_map = New-Object XML
$java_update_map.Load($update_map_url)
}
catch [System.Net.WebException]
{
Write-Warning "Failed to access $update_map_url"
$empty_line | Out-String
Return "Exiting without checking the latest Java version numbers or without updating Java (at Step 10)."
}
# Update Chart:
$update_chart = $java_update_map.SelectNodes("/java-update-map/mapping")
$update_chart | Export-Csv $path\java_update_chart.csv -Delimiter ';' -NoTypeInformation -Encoding UTF8
# Step 11
# Check the Info on the most recent Java version Home Page (XML) by connecting to the Java/Oracle website (Page 3, The Home Page)
# https://javadl-esd-secure.oracle.com/update/1.8.0/au-descriptor-1.8.0_111-b14.xml
$most_recent_xml_home_page = ($java_update_map.SelectNodes("/java-update-map/mapping") | Select-Object -First 1).url
try
{
$xml_info = New-Object XML
$xml_info.Load($most_recent_xml_home_page)
}
catch [System.Net.WebException]
{
Write-Warning "Failed to access $most_recent_xml_home_page"
$empty_line | Out-String
Return "Exiting without checking the latest Java version numbers or without updating Java (at Step 11)."
}
# Further Info URL:
$further_info_url = $xml_info.SelectNodes("/java-update/information") | Select-Object -First 1 | Select-Object -ExpandProperty moreinfo
# Description:
$description = $xml_info.SelectNodes("/java-update/information") | Select-Object -First 1 | Select-Object -ExpandProperty descriptionfrom8
# Current Version (Full, with an underscore and a dash: x.y.z_nnn-abc):
# 1.8.0_111-b14
$current_version_build = ($xml_info.SelectNodes("/java-update/information") | Select-Object -First 1 | Select-Object -ExpandProperty version)[-1]
# Most Recent Java Version
$most_recent_java_version = [string]'Java ' + $current_main_version + ' Update ' + $current_update_number
# Most Recent Build
$current_build_number = $current_version_build.Split("-")[-1]
# Download URL:
# http://javadl.oracle.com/webapps/download/GetFile/1.8.0_111-b14/windows-i586/jre-8u111-windows-au.exe
# Source: http://stackoverflow.com/questions/27175137/powershellv2-remove-last-x-characters-from-a-string#32608908
$download_url = $xml_info.SelectNodes("/java-update/information") | Select-Object -First 1 | Select-Object -ExpandProperty url
$powershell_version = $PSVersionTable.PSVersion
If (($download_url.EndsWith("/")) -eq $true) { $download_url = $download_url -replace ".{1}$" } Else { $continue = $true }
If (($powershell_version.Major -ge 5) -and ($powershell_version.Minor -ge 1)) {
$root_url = (Split-Path $download_url -Parent).Replace("\", "/")
} Else {
$filename = $download_url.Split("/")[-1]
$root_url = $download_url.Replace("/$filename", "")
} # Else (If $PSVersionTable.PSVersion)
# Custom Download URL:
$custom_download_url = [string]$root_url + "/xpiinstall.exe"
# Full 32-bit Download URL:
$full_32_download_url = [string]$root_url + "/jre-" + $current_main_version + "u" + $current_update_number + "-windows-i586.exe"
# Full 64-bit Download URL:
$full_64_download_url = [string]$root_url + "/jre-" + $current_main_version + "u" + $current_update_number + "-windows-x64.exe"
$obj_most_recent += New-Object -TypeName PSCustomObject -Property @{
'Most Recent Version' = $most_recent_java_version
'Most Recent Java Main Version' = [int32]$current_main_version
'Most Recent Java Update Number' = [int32]$current_update_number
'Most Recent Build' = $current_build_number
'Most Recent Build (Legacy Name, Full)' = $current_version_build
'Most Recent Version (Legacy Name)' = $current_version_full
'Description' = $description
'Further Info' = $further_info_url
'Java Uninstall Tool URL' = $uninstaller_tool_url
'Download URL' = $download_url
'Custom Download URL' = $custom_download_url
'Full 32-bit Download URL' = $full_32_download_url
'Full 64-bit Download URL' = $full_64_download_url
} # New-Object
$obj_most_recent.PSObject.TypeNames.Insert(0,"Most Recent non-beta Java Version Available")
$obj_most_recent_selection = $obj_most_recent | Select-Object 'Most Recent Version','Most Recent Java Main Version','Most Recent Java Update Number','Most Recent Build','Most Recent Version (Legacy Name)','Description','Further Info','Java Uninstall Tool URL','Download URL','Custom Download URL','Full 32-bit Download URL','Full 64-bit Download URL'
# Display the most recent Java version numbers in console
$empty_line | Out-String
$header_most_recent = "Most Recent non-beta Java Version Available"
$coline_most_recent = "-------------------------------------------"
Write-Output $header_most_recent
$coline_most_recent | Out-String
Write-Output $obj_most_recent_selection
# Step 12
# Try to determine which Java versions, if any, are outdated and need to be updated.
$downloading_java_is_required = $false
$downloading_java_32_is_required = $false
$downloading_java_64_is_required = $false
If ($java_is_installed -eq $true) {
$most_recent_32_bit_java_already_exists = Check-InstalledSoftware "Java $current_main_version Update $current_update_number"
$most_recent_64_bit_java_already_exists = Check-InstalledSoftware "Java $current_main_version Update $current_update_number (64-bit)"
$java_auto_updater_exists = Check-InstalledSoftware "Java Auto Updater"
$all_32_bit_javas = $java_enumeration | Where-Object { $_.Type -eq "32-bit" }
$number_of_32_bit_javas = ($all_32_bit_javas | Measure-Object).Count
$all_64_bit_javas = $java_enumeration | Where-Object { $_.Type -eq "64-bit" }
$number_of_64_bit_javas = ($all_64_bit_javas | Measure-Object).Count
# 32-bit
If ($32_bit_java_is_installed -eq $false) {
$continue = $true
} ElseIf (($32_bit_java_is_installed -eq $true) -and ($most_recent_32_bit_java_already_exists) -and ($number_of_32_bit_javas -eq 1)) {
# $downloading_java_32_is_required = $false