Jump to content

Function Not Working


Recommended Posts

Hi there,

this code is not running well:

#Installation of UG NX4 with checking the logfiles

#Read Registry Value UGII_BASE_DIR, UGII_Root_DIR and bct_eoms_dir

$UGIIBASE_DIR = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_BASE_DIR")

$UGII_Root_DIR = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_Root_DIR")

$BCT_EOMS_DIR = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "BCT_EOMS_DIR")

Func Installscript()

#Start Installscript Installation

Runwait (@SystemDir & "\msiexec.exe /i" & @ScriptDir & "\ISScript10.Msi" & " /qn /li c:\gb\ugnx4scriptenginel.log")

RunWait ("c:\gb\stringconverter.exe ugnx4scriptenginel.log ugnx4scriptengine.log /ansi")

$file = ("c:\gb\ugnx4scriptengine.log")

$var = FileRead($file, FileGetSize($file))

if StringInStr($var, "Installation operation completed successfully") then

Return 1 ;mit Rückgabewert: Bedingung "true"

Else

Return ;ohne Rückgabewert: Bedingung "false"

EndIf

EndFunc

Func UGNX4Install()

RunWait (@SystemDir & "\msiexec.exe /qn /i" & @ScriptDir & "\UGSNX40.msi" & "ADDLOCAL=all SETUPTYPE=typical LANGUAGE=german INSTALLDIR=c:\ugs\nx40 LICENSESERVER=27000@ugtestcdcixpgbk /li c:\gb\ugnx4install.log")

RunWait ("c:\gb\stringconverter.exe ugnx4install.log ugnx4instal.log /ansi")

$file = ("c:\gb\ugnx4instal.log")

$var = FileRead($file, FileGetSize($file))

if StringInStr($var, "Installation operation completed successfully") then

Return 1

Else

Return

EndIf

EndFunc

Func UGDoku()

RunWait (@SystemDir & "\msiexec.exe /i" & @ScriptDir & "\UGS NX 4.0 Documentation.msi" & " INSTALLDIR=c:\ugs\nx40 /qn /li c:\gb\ugnx4doku.log")

RunWait ("c:\gb\stringconverter.exe ugnx4doku.log ugnx4dok.log /ansi")

$file = ("c:\gb\ugnx4dok.log")

$var = FileRead($file, FileGetSize($file))

if StringInStr($var, "Installation operation completed successfully") then

Return 1

Else

Return

EndIf

EndFunc

Func BCTInstall()

RunWait (@ScriptDir & "\bct\Disk1\Setup.exe /s /f1" & @ScriptDir & "\bct\Disk1\setup.iss" & "/f2" & "c:\gb\bctv9.log")

RunWait ("c:\gb\stringconverter.exe bctv9.log bctv_9.log /ansi")

$file = ("c:\gb\bctv_9.log")

$var = FileRead($file, FileGetSize($file))

if StringInStr($var, "ResultCode=0") then

Return 1

Else

Return

EndIf

EndFunc

If Installscript() Then ;Function is running if the vaulue is: 1)

If UGNX4Install() Then

UGDoku()

ElseIf UGNX4Install()then

MsgBox (1, "Installation" , "Die Installation von UGNX4 ist fehlgeschlagen")

IF UGDoku() Then

BCTInstall()

If BCTInstall() Then

RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_BASE_DIR", "REG_SZ", $UGIIBASE_DIR)

RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_Root_DIR", "REG_SZ", $UGII_Root_DIR)

RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "BCT_EOMS_DIR", "REG_SZ", $BCT_EOMS_DIR)

FileDelete (@StartMenuCommonDir & "UG NX4.lnk")

EndIf

ElseIf UGDoku() Then

MsgBox (1, "Installation" , "Die Installation von UGNX4 Doku ist fehlgeschlagen")

EndIf

EndIf

ElseIf InstallScript() Then

MsgBox (1, "Installation" , "Die Installation von UGNX4 Installscript ist fehlgeschlagen")

EndIf

I'm new in Autoit - so I cannot find the mistake ! Function Installscript is running but non of the following functions !

Link to comment
Share on other sites

HI,

I cannot test it, but maybe you get a step forward if you put some flags in your code. Like ConsoleWrite() and then you look how far you get.

ConsoleWrite worls well in Scite, if you don't use it, change to e.g.: ToolTip()

Hope that helps.

$UGIIBASE_DIR = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_BASE_DIR")
$UGII_Root_DIR = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_Root_DIR")
$BCT_EOMS_DIR = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "BCT_EOMS_DIR")

Func Installscript()
    #Start Installscript Installation
    RunWait(@SystemDir & "\msiexec.exe /i" & @ScriptDir & "\ISScript10.Msi" & " /qn /li c:\gb\ugnx4scriptenginel.log")
    RunWait("c:\gb\stringconverter.exe ugnx4scriptenginel.log ugnx4scriptengine.log /ansi")
    $file = ("c:\gb\ugnx4scriptengine.log")
    $var = FileRead($file, FileGetSize($file))
    If StringInStr($var, "Installation operation completed successfully") Then
        Return 1;mit Rückgabewert: Bedingung "true"
    Else
        Return;ohne Rückgabewert: Bedingung "false"
    EndIf
EndFunc  ;==>Installscript

Func UGNX4Install()
    ConsoleWrite("Step 2")
    RunWait(@SystemDir & "\msiexec.exe /qn /i" & @ScriptDir & "\UGSNX40.msi" & "ADDLOCAL=all SETUPTYPE=typical LANGUAGE=german INSTALLDIR=c:\ugs\nx40 LICENSESERVER=27000@ugtestcdcixpgbk /li c:\gb\ugnx4install.log")
    ConsoleWrite("Step 3")
    RunWait("c:\gb\stringconverter.exe ugnx4install.log ugnx4instal.log /ansi")
    ConsoleWrite("Step 4")
    $file = ("c:\gb\ugnx4instal.log")
    $var = FileRead($file, FileGetSize($file))
    If StringInStr($var, "Installation operation completed successfully") Then
        Return 1
    Else
        Return
    EndIf
EndFunc  ;==>UGNX4Install

Func UGDoku()
    RunWait(@SystemDir & "\msiexec.exe /i" & @ScriptDir & "\UGS NX 4.0 Documentation.msi" & " INSTALLDIR=c:\ugs\nx40 /qn /li c:\gb\ugnx4doku.log")
    RunWait("c:\gb\stringconverter.exe ugnx4doku.log ugnx4dok.log /ansi")
    $file = ("c:\gb\ugnx4dok.log")
    $var = FileRead($file, FileGetSize($file))
    If StringInStr($var, "Installation operation completed successfully") Then
        Return 1
    Else
        Return
    EndIf
EndFunc  ;==>UGDoku

Func BCTInstall()
    RunWait(@ScriptDir & "\bct\Disk1\Setup.exe /s /f1" & @ScriptDir & "\bct\Disk1\setup.iss" & "/f2" & "c:\gb\bctv9.log")
    RunWait("c:\gb\stringconverter.exe bctv9.log bctv_9.log /ansi")
    $file = ("c:\gb\bctv_9.log")
    $var = FileRead($file, FileGetSize($file))
    If StringInStr($var, "ResultCode=0") Then
        Return 1
    Else
        Return
    EndIf
EndFunc  ;==>BCTInstall

If Installscript() Then;Function is running if the vaulue is: 1)
    ConsoleWrite("Step 1")
    If UGNX4Install() Then
        ConsoleWrite("Step 5")
        UGDoku()
        ConsoleWrite("Step 6")
    ElseIf UGNX4Install() Then
        MsgBox(1, "Installation", "Die Installation von UGNX4 ist fehlgeschlagen")
        If UGDoku() Then
            BCTInstall()
            If BCTInstall() Then
                RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_BASE_DIR", "REG_SZ", $UGIIBASE_DIR)
                RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_Root_DIR", "REG_SZ", $UGII_Root_DIR)
                RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "BCT_EOMS_DIR", "REG_SZ", $BCT_EOMS_DIR)
                FileDelete(@StartMenuCommonDir & "UG NX4.lnk")
            EndIf
        ElseIf UGDoku() Then
            MsgBox(1, "Installation", "Die Installation von UGNX4 Doku ist fehlgeschlagen")
        EndIf
    EndIf
ElseIf Installscript() Then
    MsgBox(1, "Installation", "Die Installation von UGNX4 Installscript ist fehlgeschlagen")
EndIf

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I see possible issues with no quotes when using @ScriptDir maco, if spaces are within the path.

I also see logic issue with your If statement at the end of the script. You repeatedly use an ElseIf on the same condition :think: like below.

If Func1() Then

ElseIf Func1() Then

EndIf

Using only Else would prevent a 2nd call to the function to execute again.

This is what I have changed:

#Installation of UG NX4 with checking the logfiles

#Read Registry Value UGII_BASE_DIR, UGII_Root_DIR and bct_eoms_dir

$UGIIBASE_DIR = RegRead ("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_BASE_DIR")
$UGII_Root_DIR = RegRead ("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_Root_DIR")
$BCT_EOMS_DIR = RegRead ("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "BCT_EOMS_DIR")

Func Installscript()
    #Start Installscript Installation
    Runwait (@SystemDir & '\msiexec.exe /i "' & @ScriptDir & '\ISScript10.Msi" /qn /li c:\gb\ugnx4scriptenginel.log')
    RunWait ("c:\gb\stringconverter.exe ugnx4scriptenginel.log ugnx4scriptengine.log /ansi")
    $file = ("c:\gb\ugnx4scriptengine.log")
    $var = FileRead($file, FileGetSize($file))
    if StringInStr($var, "Installation operation completed successfully") then
        Return 1;mit Rückgabewert: Bedingung "true"
    Else
        Return;ohne Rückgabewert: Bedingung "false"
    EndIf
EndFunc

Func UGNX4Install()
    RunWait (@SystemDir & '\msiexec.exe /qn /i "' & @ScriptDir & '\UGSNX40.msi ADDLOCAL=all SETUPTYPE=typical LANGUAGE=german INSTALLDIR=c:\ugs\nx40 LICENSESERVER=27000@ugtestcdcixpgbk /li c:\gb\ugnx4install.log')
    RunWait ("c:\gb\stringconverter.exe ugnx4install.log ugnx4instal.log /ansi")
    $file = ("c:\gb\ugnx4instal.log")
    $var = FileRead($file, FileGetSize($file))
    if StringInStr($var, "Installation operation completed successfully") then
        Return 1
    Else
        Return
    EndIf
EndFunc

Func UGDoku()
    RunWait (@SystemDir & '\msiexec.exe /i "' & @ScriptDir & '\UGS NX 4.0 Documentation.msi" INSTALLDIR=c:\ugs\nx40 /qn /li c:\gb\ugnx4doku.log')
    RunWait ("c:\gb\stringconverter.exe ugnx4doku.log ugnx4dok.log /ansi")
    $file = ("c:\gb\ugnx4dok.log")
    $var = FileRead($file, FileGetSize($file))
    if StringInStr($var, "Installation operation completed successfully") then
        Return 1
    Else
        Return
    EndIf
EndFunc

Func BCTInstall()
    RunWait (@ScriptDir & '\bct\Disk1\Setup.exe /s /f1"' & @ScriptDir & '\bct\Disk1\setup.iss /f2"c:\gb\bctv9.log"')
    RunWait ("c:\gb\stringconverter.exe bctv9.log bctv_9.log /ansi")
    $file = ("c:\gb\bctv_9.log")
    $var = FileRead($file, FileGetSize($file))
    if StringInStr($var, "ResultCode=0") then
        Return 1
    Else
        Return
    EndIf
EndFunc

If Installscript() Then;Function is running if the vaulue is: 1)
    If UGNX4Install() Then
        UGDoku()
    Else;If UGNX4Install() then
        MsgBox (1, "Installation" , "Die Installation von UGNX4 ist fehlgeschlagen")
        IF UGDoku() Then
    ;BCTInstall()
            If BCTInstall() Then
                RegWrite ("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_BASE_DIR", "REG_SZ", $UGIIBASE_DIR)
                RegWrite ("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "UGII_Root_DIR", "REG_SZ", $UGII_Root_DIR)
                RegWrite ("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "BCT_EOMS_DIR", "REG_SZ", $BCT_EOMS_DIR)
                FileDelete (@StartMenuCommonDir & "UG NX4.lnk")
            EndIf
        Else;If UGDoku() Then
            MsgBox (1, "Installation" , "Die Installation von UGNX4 Doku ist fehlgeschlagen")
        EndIf
    EndIf
Else;If InstallScript() Then
    MsgBox (1, "Installation" , "Die Installation von UGNX4 Installscript ist fehlgeschlagen")
EndIf

Edit:

Perhaps hard to see in the code, but I have broken your ElseIf's by a comment char ";" to convert to Else only.

Edited by MHz
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...