PowerShell: Java 7 install

From ICO wiki
Jump to navigationJump to search

<Source lang="powershell">

<#

   .SYNOPSIS
       	java instal skript
       
   .DESCRIPTION

kui arvutis pole java 7 kausta siis tomatakse alla java ja instalitakse see. ajutine kaust mis lootakse kustutatakse kui instal on onestunud. installib java 32bit win 64bit operatsioonisüsteemile.

	.AUTHOR

Priit Lilleleht

  1. >


  1. tompab alla java

function javaDL { echo "laen alla java" $storageDir = "C:\tempjava" $webclient = New-Object System.Net.WebClient $url = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=63691" $file = "$storageDir\javanew.exe" $webclient.DownloadFile($url,$file)

instaljava }

  1. installib java ja kirjudab logi faili

Function instaljava { echo "instaling java" $logi = "C:\tempjava\javasetup.log" $command = "cmd.exe /c start /w C:\tempjava\javanew.exe /s /L $logi" $process = [WMICLASS]"\\.\ROOT\CIMV2:win32_process" $process.Create($command)

  1. ootab kuni CMD aken sulgub

$ErrorActionPreference = "SilentlyContinue" do {} While (get-process cmd | select -Property Responding)

#anab teada kas instal onestus if (!(get-childitem $logi | select-string "error status: 0" | foreach {$_.line})) { echo "java instal ebaonestus proovike uuesti" } else { Remove-Item C:\tempjava -recurse echo "java on instalitud" } }

  1. loob ajutise kausta kuhu java alla tomatakse

function lookaust { if (!(Test-Path -path C:\tempjava\)) {

  		New-Item C:\tempjava\ -type directory
  		javaDL
  	} 

else {javaDL} }

  1. kontrolib kas java 7 on arvutis

if (!(Test-Path -Path 'C:\Program Files (x86)\Java\jre7')) { lookaust

} else { "java 7 on juba arvutise instalitud" }