Orara

Hi Im new here, Just want to share a nice script with you

29 posts in this topic

#1 ·  Posted (edited)

Hi,

Im Work as an IT guy,

Lately im to lazy to install Java for our clients machine (Update)

Here is the script.

This is my first script that i made, i will be happy to get some advice from more experience people,

; This Script will cehck the Java version on this conputer, If the Verstion on the PC is an old version
; The Script will download a new version of Java and install it
; Created By Orara 8.8.2015

#RequireAdmin
#include <InetConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>


MsgBox (0 , "New Java installtopm", "This Script created by Orara, Click OK to Continue")
;test script to download java and install it.
DLjava()

Func DLjava()
   ; $fDlVer Check the version that stored in the ROOT dir of the script (the installtion)
   Local $fDlVer = FileGetVersion ( "Java - Setup.exe" )
   ; Check the version on the computer, this path is the path of Java 8 and above
   Local $PC_Vertion = FileGetVersion ( "C:\ProgramData\Oracle\Java\javapath\javaws.exe",  $FV_PRODUCTVERSION )

;   Visual text of the versions on the computer (This is created for testing if everything works)
;   MsgBox (0, "Java", "Download version: " & $fDlVer )
;   MsgBox ( 0, "Computer version" , "The Computer Version is: " & $PC_Vertion )

; Chrck the Java Version on the Clint Mchine
      If $fDlVer == $PC_Vertion Then
         MsgBox (0, "Java is up to date", "You have the newest version of Java on your PC", 5)
         Return False
      Else
         MsgBox (0, "Old Java", "You Have an old version of java, Click OK to Continue", 10)
         InetGet ("http://javadl.sun.com/webapps/download/AutoDL?BundleId=107944", "Java - Setup.exe", $INET_DOWNLOADWAIT )
         MsgBox (0, "New Java version as been Download","Installtion will start, Click OK to Continue" )
         ; this Code will install Java.exe with half user entercations
         ShellExecute ( "Java - Setup.exe" )
         WinWaitActive ( "Java Setup - Welcome" , "Change destination folder" )
         ControlClick (  "Java Setup - Welcome" , "Change destination folder" , 1 )

         WinWaitActive ( "Java Setup - Complete" , "You have successfully installed Java" )
         ControlClick (  "Java Setup - Complete" , "You have successfully installed Java" , 2 )
      EndIf

 

What you Think?,

Again this is my first script,

 

Have a nice Day,

Or

 

 

Edited by Orara

Share this post


Link to post
Share on other sites



What I noticed on a first quick check is that your script lacks any form of error checking.
Imagine the download of the new Java version failed or Oracle decided to change the Window titles or ... Your script will hang and nobody knows why.
So I suggest to check after each AutoIt command for errors, write a MsgBox in case of an error describing what happened and exit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What I noticed on a first quick check is that your script lacks any form of error checking.
Imagine the download of the new Java version failed or Oracle decided to change the Window titles or ... Your script will hang and nobody knows why.
So I suggest to check after each AutoIt command for errors, write a MsgBox in case of an error describing what happened and exit.

One problem was fix,

Func DLjava()
   ; $fDlVer Check the version that stored in the ROOT dir of the script (the installtion)
   Local $fDlVer = FileGetVersion ( "Java - Setup.exe" )
   ; Check the version on the computer, this path is the path of Java 8 and above
   Local $PC_Vertion = FileGetVersion ( "C:\ProgramData\Oracle\Java\javapath\javaws.exe",  $FV_PRODUCTVERSION )
   Local $fExists = "C:\ProgramData\Oracle\Java\javapath\javaws.exe"

   If FileExists ( $fExists ) Then
      MsgBox (0 , "Java File Exist", "PC verstion found installtion will Continue")
   Else
      MsgBox ( 0, "Cant Fint PC File", "Cant find PC file, installtion will stop")
      Exit
   EndIf

Im working on the other problems , Like the link and the title

 

Share this post


Link to post
Share on other sites

Change the order of FileGetVersion and FileExists. FileGetversion will fail if the file does not exist.

Func DLjava()
    ; $sDownloadVersion. Check the version that's stored in the ROOT dir of the script (the installation)
    Local $iDownloadVersion = FileGetVersion("Java - Setup.exe", $FV_PRODUCTVERSION)
    ; Check the version on the computer, this path is the path of Java 8 and above
    Local $sLocalFile = "C:\ProgramData\Oracle\Java\javapath\javaws.exe"
    If FileExists($sLocalFile) Then
        $iLocalVersion = FileGetVersion($sLocalFile, $FV_PRODUCTVERSION)
        MsgBox (0 , "Java Insallation - Information", "PC verstion found, installation will continue")
    Else
        MsgBox ( 0, "Java Insallation - Error", "Can't find PC file, installation will stop")
        Exit
    EndIf

You will notice that I changed the variable names a bit. Now they adhere to the Hungarian notation, which is recommended here.
I've added $FV_PRODUCTVERSION to the first FileGetVersion as well.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

BTW: You could use the command line switch "/s" to silently install Java. This means no automation of Java installation windows is needed.
This makes your script more reliable.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

BTW: You could use the command line switch "/s" to silently install Java. This means no automation of Java installation windows is needed.
This makes your script more reliable.

Thinks for the information , its help me a lot,

 

I Made a few temporary cheanges,

; This Script will cehck the Java version on this conputer, If the Verstion on the PC is an old version
; The Script will download a new version on Java and install it
; Created By Orara 8.8.2015

#RequireAdmin
#include <InetConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>


MsgBox (0 , "New Java installtopm", "This program Made by Orara, Click OK to Continue")
;test script to download java and install it.
DLjava()

Func DLjava()
   ; $iDownloadVersion Check the version that stored in the ROOT dir of the script (the installtion)
   Local $iDownloadVersion = FileGetVersion ( "Java - Setup.exe" , $FV_PRODUCTVERSION )
   ; Check the version on the computer, this path is the path of Java 8 and above
   Local $PC_Vertion = FileGetVersion ( "C:\ProgramData\Oracle\Java\javapath\javaws.exe",  $FV_PRODUCTVERSION )
   ; Ver to check if Java file is exists on the PC.
   Local $sLocalFile = "C:\ProgramData\Oracle\Java\javapath\javaws.exe"
   Local $Size = FileGetSize ( "Java - Setup.exe" )

; Check the file on the pc, If the file dosnt exists, the script will stop
   If FileExists ( $sLocalFile ) Then
      MsgBox (0 , "Java Insallation - Information", "PC verstion found, installation will continue")
   Else
      MsgBox ( 0, "Java Insallation - Error", "Can't find PC file, installation will stop")
      Exit
     EndIf

;   Visual text of the versions on the computer (This is created for testing if everything works)
;   MsgBox (0, "Java", "Download version: " & $iDownloadVersion )
;   MsgBox ( 0, "Computer version" , "The Computer Version is: " & $PC_Vertion )

; Chrck the Java Version on the Clint Mchine
      If $iDownloadVersion == $PC_Vertion Then
         MsgBox (0, "Java is up to date", "You have the newest version of Java on your PC", 5)
         Return False
      Else
         MsgBox (0, "Old Java", "You Have an old version of java, Click OK to Continue" , 10)
         InetGet ("http://javadl.sun.com/webapps/download/AutoDL?BundleId=107944", "Java - Setup.exe", $INET_DOWNLOADWAIT )

         If FileExists ( "Java - Setup.exe" ) & $Size < 4096 Then
            MsgBox ( 0, "File Exist", "Your file has been downloaded successfully installation will Continue")
         Else
            MsgBox ( 0, "File dont Exist", "Java - Setup.exe not found, installtion will stop")
            Exit
            EndIf

         MsgBox (0, "New Java version as been Download","Installtion will start, Click OK to Continue" )
         ; this Code will install Java.exe with half user entercations
         ShellExecute ( "Java - Setup.exe" )
         WinWaitActive ( "Java Setup - Welcome" , "Change destination folder" )
         ControlClick (  "Java Setup - Welcome" , "Change destination folder" , 1 )

         WinWaitActive ( "Java Setup - Complete" , "You have successfully installed Java" )
         ControlClick (  "Java Setup - Complete" , "You have successfully installed Java" , 2 )
      EndIf

I just don't  way you added,

If FileExists($sLocalFile) Then
        $iLocalVersion = FileGetVersion($sLocalFile, $FV_PRODUCTVERSION)

        MsgBox (0 , "Java Insallation - Information", "PC verstion found, installation will continue")
    Else

I'll be happy if you explain this to me, 

I'll continue tomorrow,

Thank you very much for the help!.

i learned a lot.

Share this post


Link to post
Share on other sites

The code means: First check if the file exists, then retrieve the file version. Because if the file does not exist then getting the file version is not sensible.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The code means: First check if the file exists, then retrieve the file version. Because if the file does not exist then getting the file version is not sensible.

i didn't think about this,

This is make sense.

Thank you :)

Share this post


Link to post
Share on other sites

Another thing:
I wouldn't check for FileExists after downloading Java. It might exist from a former run. Check the number of downloaded bytes:

$iDownloadedBytes = InetGet("http://javadl.sun.com/webapps/download/AutoDL?BundleId=107944", "Java - Setup.exe", $INET_DOWNLOADWAIT)
If $iDownloadedBytes > 0 Then
    MsgBox ( 0, "File exists", "Your file has been downloaded successfully, installation will continue.")
Else
    MsgBox ( 0, "File does not exist", "Java - Setup.exe not found, installation will stop.")
    Exit
EndIf

Why do you query

$Size < 4096 Then

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Another thing:
I wouldn't check for FileExists after downloading Java. It might exist from a former run. Check the number of downloaded bytes:

$iDownloadedBytes = InetGet("http://javadl.sun.com/webapps/download/AutoDL?BundleId=107944", "Java - Setup.exe", $INET_DOWNLOADWAIT)
If $iDownloadedBytes > 0 Then
    MsgBox ( 0, "File exists", "Your file has been downloaded successfully, installation will continue.")
Else
    MsgBox ( 0, "File does not exist", "Java - Setup.exe not found, installation will stop.")
    Exit
EndIf

Why do you query

$Size < 4096 Then

i check the query because somethings the file only download 2 mb size, this cause a pproblems. Because the file exists but it's Corrupted

Share this post


Link to post
Share on other sites

To make sure the file was fully downloaded first retrieve the size of the file:

Local $sURL = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=107944"
$iDownloadSize = InetGetSize($sURL)
If @error <> 0 Then Exit MsgBox ( 0, "Error", "Could not retrieve the size of the Java download.")
$iDownloadedBytes = InetGet($sURL, "Java - Setup.exe", $INET_DOWNLOADWAIT)
If $iDownloadedBytes = $iDownloadSize Then
    MsgBox ( 0, "File exists", "Your file has been downloaded successfully, installation will continue.")
Else
    MsgBox ( 0, "File does not exist", "Java - Setup.exe not found, installation will stop.")
    Exit
EndIf

 

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Nice, I didn't know that autoit have an option like IntGetSize().

And want is the @error mean?

Share this post


Link to post
Share on other sites

The help file is your friend ;)

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yea l read a lot from Google, always get to the help, but not always find the answers in looking for,

Again thank you, you help me a lot

Share this post


Link to post
Share on other sites

When using SciTE as editor simply point to the function you want to get help for and press F1.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What you Think?

speeling mistakes, good script at 1st attempt

 

TD :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Ah, now I get it: "spelling" mistakes ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Sorry my English is not very good,

I will try to fix all the spelling mistakes in the next commends.

Edited by Orara

Share this post


Link to post
Share on other sites

The longer you are on this forum the more your English will improve :)
It is not necessary to speak perfect English on this forum, you just need to be able to tell us what your problem is. Use Google translate if you are unsure.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The longer you are on this forum the more your English will improve :)
It is not necessary to speak perfect English on this forum, you just need to be able to tell us what your problem is. Use Google translate if you are unsure.

I can confirm.
Actually, I still using Google Translate, but now after a few years, I write in english, and checking the meaning in my native language - Polish.

Keep learning @Orara

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now