Jump to content
Sign in to follow this  
Brentp

Can you join a count to a variable

Recommended Posts

Brentp

Sorry if I use the wrong words as Im new to coding

What I want to do is define some variables which are files, then have a counter to move onto the next variable

eg

$FileName1 = 'autoexec1.bat'

$FileName2 = 'autoexec2.bat'

$FileName3 = 'autoexec3.bat'

MsgBox(0, "File Name", "The file is " & $FileName1)

Then it would say autoexec1.bat in the box

then have something that will change the $FileName1 to FileName2

Then say another message box that would say autoexec2.bat

and so on

Or can I do something like

FileName + $Count = $FileName1 = 'autoexec1.bat'

FileName + $Count = $FileName2 = 'autoexec2.bat'

$Count = '1'

Hope this makes sense to someone.

Share this post


Link to post
Share on other sites
dani

$sFileName = "autoexec"
For $iCount = 1 To 3
  MsgBox(0, "", $sFileName & $iCount & ".bat")
Next

Edited by dani

Share this post


Link to post
Share on other sites
martin

Sorry if I use the wrong words as Im new to coding

What I want to do is define some variables which are files, then have a counter to move onto the next variable

eg

$FileName1 = 'autoexec1.bat'

$FileName2 = 'autoexec2.bat'

$FileName3 = 'autoexec3.bat'

MsgBox(0, "File Name", "The file is " & $FileName1)

Then it would say autoexec1.bat in the box

then have something that will change the $FileName1 to FileName2

Then say another message box that would say autoexec2.bat

and so on

Or can I do something like

FileName + $Count = $FileName1 = 'autoexec1.bat'

FileName + $Count = $FileName2 = 'autoexec2.bat'

$Count = '1'

Hope this makes sense to someone.

Welcome to the AuitoIt forums Brentp :mellow:

What you need is arrays and string concatenation. Eg

Dim $FileName[100]
for $n = 0 to 99
$Filename[$n] = "autoexec" & $n & ".bat"
next

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Brentp

Hey Dani, Is that just printing or does that allow me to use the variable

This is what Iam trying to achieve,

I want a script that will go and check if MS hotfixes are installed, if not then it will run it.

The below is a bit messed up, cause Ive been trying to figure it out.

But I was aiming for It would read the first hotfix name and then check the registry, it would then install it if it didnt exist it would then move on to the next hotfix and check that.

It would also keep a count of how many it did and didnt install.

this is the best my brain could come up with, I was just going to set just do one set of code that would have a hotfix name and then just copy and paste it changing the name each time, but that seemed messy and I figured that this was would be neater (but its harder)

Heres what ive got

$Hotfix1 = 'KB952004'

$FileName1 = 'WindowsXP-KB952004-x86-ENU.exe'

$Hotfix2 = 'KB955759'

$FileName2 = 'WindowsXP-KB955759-x86-ENU.exe'

$Hotfix3 = 'KB956572'

$FileName3 = 'WindowsXP-KB956572-x86-ENU.exe'

$Count = '0'

$Count2 = '0'

$1CmdLine = '/u /z'

Func Start ( )

$Patch = RegRead ( 'HKEY_LOCAL_MACHINE\' & 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\'& $Hotfix, 'Installed' )

If NOT $Patch = '1' then

Install ( )

Else

FixOK ( )

EndIf

EndFunc

Func Install ( )

SplashTextOn("Hot Fix Not Installed", "Installing " & $Hotfix & " Please Wait", 450, 90)

Sleep (1000)

SplashOff ( )

$path = @WorkingDir & "\" & $FileName

RunWait('"' & $path & '" ' & $1CmdLine, "C:\WINDOWS", @SW_MAXIMIZE)

EndFunc

$Patch = RegRead ( 'HKEY_LOCAL_MACHINE\' & 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\'& $Hotfix, 'Installed' )

If NOT $Patch = '1' then

$count2 += '1'

MsgBox(0, "Error", "There was an error installing " & $Hotfix, 450, 90)

Else

$count += '1'

EndIf

Func FixOk ( )

$count2 += '1'

SplashTextOn("Hot Fix Installed", "Hot Fix " & $Hotfix & " Is Installed", 450, 90)

Sleep (1500)

SplashOff ( )

EndFunc

If NOT $Hotfix = '$Hotfix & 3' then

End ( )

Else

$Hotfix += & '1'

Start ( )

EndIf

Func End ( )

MsgBox(0, "Hotfix Installer", "Total Hotfixes Installed = " & $Count)

EndFunc

Share this post


Link to post
Share on other sites
martin

I think you need to learn about arrays because they make life a lot simpler.

Not tested but just an approach.

Dim $Hotfix = StringSplit('KB952004|KB955759|KB956572',"|")
Dim $FileName = StringSplit('WindowsXP-KB952004-x86-ENU.exe|WindowsXP-KB955759-x86-ENU.exe|WindowsXP-KB956572-x86-ENU.exe',"|")

$1CmdLine = '/u /z'
Start()


Func Start()
    Local $j, $Patch, $Count = 0
    For $j = 1 To UBound($Hotfix) - 1
        $Patch = RegRead('HKEY_LOCAL_MACHINE\' & 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\' & $Hotfix[$j], 'Installed')
        If Not $Patch = '1' Then
            Install($j)
            $Count += 1
        Else
            FixOk($j)
        EndIf
    Next
    MsgBox(0, "Hotfix Installer", "Total Hotfixes Installed = " & $Count)
EndFunc ;==>Start

Func Install($iI)
    Local $path
    SplashTextOn("Hot Fix Not Installed", "Installing " & $Hotfix[$iI] & " Please Wait", 450, 90)
    Sleep(1000)
    SplashOff()
    $path = @WorkingDir & "\" & $FileName[$iI]
    RunWait('"' & $path & '" ' & $1CmdLine, "C:\WINDOWS", @SW_MAXIMIZE)
EndFunc ;==>Install

Func FixOk($iI)

    SplashTextOn("Hot Fix Installed", "Hot Fix " & $Hotfix[$iI] & " Is Installed", 450, 90)
    Sleep(1500)
    SplashOff()
EndFunc ;==>FixOk

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Brentp

Thanks Martin, That works

I want to go through and add some error checking to see if a patch installed or not, but now my project ideas are getting bigger and bigger.

This is fun stuff.

Another question for someone, when you use Koda and generate it, it wipes out any code that you added to your project, are you supposed to do your gui first then add the code or is there someway to make changes to the GUI then it can just update the script leaving the existing code in place.

Brent

Share this post


Link to post
Share on other sites
Nurav

Following will create...

variable1

variable2

variable3

variable4

variable5

automatically using for loop. Is that what you are looking for?

for $i=1 to 5
Assign ( "variable"&$i, $i*2)
Next

MsgBox("","",$variable1&@crlf&$variable2&@crlf&$variable3&@crlf&$variable4&@crlf&$variable5)

Share this post


Link to post
Share on other sites
Brentp

Hey Martin,

Iam having trouble with the below code, This is the same code as yours above (which works) but the location of this hotfix is different so I have changed the regread to relfect the location where the hotfix is.

But it does not seem to be reading that this key exists in the registry so it reinstalls the hotfix each time.

any ideas

Dim $Hotfix = StringSplit('KB963707',"|")
Dim $FileName = StringSplit('KB963707.exe',"|")

$1CmdLine = '/passive /norestart'
Start()


Func Start()
    Local $j, $Patch, $Count = 0
    For $j = 1 To UBound($Hotfix) - 1
        $Patch = RegRead('HKEY_LOCAL_MACHINE\' & 'SOFTWARE\Microsoft\Updates\Microsoft .NET Framework 3.5 SP1\SP1\' & $Hotfix[$j], 'Installed')
        If Not $Patch = '1' Then
            Install($j)
            $Count += 1
        Else
            FixOk($j)
        EndIf
    Next
    MsgBox(0, "Hotfix Installer", "Total Hotfixes Installed = " & $Count)
EndFunc ;==>Start

Func Install($iI)
    Local $path
    SplashTextOn("Hot Fix Not Installed", "Installing " & $Hotfix[$iI] & " Please Wait", 450, 90)
    Sleep(1000)
    SplashOff()
    $path = @WorkingDir & "\" & $FileName[$iI]
    RunWait('"' & $path & '" ' & $1CmdLine, "C:\WINDOWS")
EndFunc ;==>Install

Func FixOk($iI)

    SplashTextOn("Hot Fix Installed", "Hot Fix " & $Hotfix[$iI] & " Is Installed", 450, 90)
    Sleep(1500)
    SplashOff()
EndFunc ;==>FixOk

Share this post


Link to post
Share on other sites
Brentp

Its Ok I finally figured it out, it was the line

$Patch = RegRead('HKEY_LOCAL_MACHINE\' & 'SOFTWARE\Microsoft\Updates\Microsoft .NET Framework 3.5 SP1\SP1\' & $Hotfix[$j], 'Installed')

The Installed key didnt exist in those patches.

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.