Jump to content
Sign in to follow this  
bdorminy

use name from list as variable

Recommended Posts

bdorminy

I am trying to write a script that will use individual names from a list as a variable. Ultimately what I want is to be able to use a list of computer names and the script can look at the list and check for a specific file, and if the file exists tell me the modified date and then go to the next computer name. What I have so far may be way off, but it almost works. The problem is it stops after the first computer name. How d I get it to go to the next name in the list until the end of the list?

$compname = IniRead ( "C:\Documents and Settings\bdorminy.DCSS\Desktop\remote file version\badsig.ini", "name", "name", "no result" )

;$compname = InputBox ( "Computer Name", "Enter Computer Name", )

$vetdat = FileGetTime( "\\" & $compname & "\C$\Program Files\CA\SharedComponents\ScanEngine\vet.dat", 0)

If @error Then

MsgBox(4096, "", "Error occurred, probably no INI file.")

EndIf

If Not @error Then

$yyyymd1 = $vetdat[0] & "/" & $vetdat[1] & "/" & $vetdat[2]

MsgBox(0, ""& $compname & " Vet.dat date", $yyyymd1, )

EndIf

Share this post


Link to post
Share on other sites
bdorminy

Ok I am now a little further along with this. I have gone in a new direction. This code seems to work however if it comes across a computer that it can not find, the loop breaks and erros out. How can I make it skip past that computer and move to the next line in the txt file?

$compname = FileOpen("C:\Documents and Settings\bdorminy.DCSS\Desktop\remote file version\badsig.txt", 0)

; Check if file opened for reading OK

If $compname = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($compname)

If @error = -1 Then ExitLoop

$vetdat = FileGetTime( "\\" & $line & "\C$\Program Files\CA\SharedComponents\ScanEngine\vet.dat", 0)

$yyyymd1 = $vetdat[0] & "/" & $vetdat[1] & "/" & $vetdat[2]

MsgBox(0, ""& $line & " Vet.dat date", $yyyymd1, )

Wend

FileClose($file)

Share this post


Link to post
Share on other sites
t0ddie

its because you tell it to exit on error.

remove that and it will continue.

do something like this instead

for $x = 1 to $file[0]

filereadline yadda yadda yadda

next

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites
bdorminy

its because you tell it to exit on error.

remove that and it will continue.

do something like this instead

for $x = 1 to $file[0]

filereadline yadda yadda yadda

next

Thanks Toddie,

I get what your saying sort of. Forgive my ignorance. This is the error I am getting, even when I take out the exit on error. It does the first few fine and then quits with this error.

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\bdorminy.DCSS\Desktop\remote file version\filever2.au3"

C:\Documents and Settings\bdorminy.DCSS\Desktop\remote file version\filever2.au3 (20) : ==> Subscript used with non-Array variable.:

$yyyymd1 = $vetdat[0] & "/" & $vetdat[1] & "/" & $vetdat[2]

$yyyymd1 = $vetdat^ ERROR

>Exit code: 0 Time: 15.023

Also, because of my ignorance, I don't know what you mean by

for $x = 1 to $file[0]

filereadline yadda yadda yadda

next

Share this post


Link to post
Share on other sites
SadBunny

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\bdorminy.DCSS\Desktop\remote file version\filever2.au3"

C:\Documents and Settings\bdorminy.DCSS\Desktop\remote file version\filever2.au3 (20) : ==> Subscript used with non-Array variable.:

$yyyymd1 = $vetdat[0] & "/" & $vetdat[1] & "/" & $vetdat[2]

$yyyymd1 = $vetdat^ ERROR

>Exit code: 0 Time: 15.023

Well since it tells you that $vetdat is a non-Array variable, I would guess that the FileGetTime fails to get the time (otherwise the $vetdat would be an array). Possibly because of access rights; accessing the C$ hidden share over a network is tricky where rights are concerned.

To troubleshoot this, please put a msgbox(0,"test","FileGetTime set the @error to: "&@error) on the line directly below the FileGetTime command, and see if the error is non-zero. (If FileGetTime fails, it will be set to 1 (see help) and FileGetTime will not return an array, and you will get your consequent error when trying to access the result variable as if it were an array.)


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
bdorminy

Well since it tells you that $vetdat is a non-Array variable, I would guess that the FileGetTime fails to get the time (otherwise the $vetdat would be an array). Possibly because of access rights; accessing the C$ hidden share over a network is tricky where rights are concerned.

To troubleshoot this, please put a msgbox(0,"test","FileGetTime set the @error to: "&@error) on the line directly below the FileGetTime command, and see if the error is non-zero. (If FileGetTime fails, it will be set to 1 (see help) and FileGetTime will not return an array, and you will get your consequent error when trying to access the result variable as if it were an array.)

The @error is indeed 1. What has happened is the computer has been turned off or taken off the network, which is fine. Now how do I get the script to skip past that one and continue on to the next line? Again forgive me for my ignorance here, My programming skills get used few and far between, so my brain works slowly at times.

Share this post


Link to post
Share on other sites
SadBunny

The @error is indeed 1. What has happened is the computer has been turned off or taken off the network, which is fine. Now how do I get the script to skip past that one and continue on to the next line? Again forgive me for my ignorance here, My programming skills get used few and far between, so my brain works slowly at times.

Just run the code based on the date only if @error = 0. Something like:

While 1
    $line = FileReadLine($compname)
    If @error = -1 Then ExitLoop
    $vetdat = FileGetTime("\\" & $line & "\C$\Program Files\CA\SharedComponents\ScanEngine\vet.dat", 0)
    If @error = 0 Then
        $yyyymd1 = $vetdat[0] & "/" & $vetdat[1] & "/" & $vetdat[2]
        MsgBox(0, "" & $line & " Vet.dat date", $yyyymd1,)
    EndIf
WEnd

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
bdorminy

Just run the code based on the date only if @error = 0. Something like:

While 1
    $line = FileReadLine($compname)
    If @error = -1 Then ExitLoop
    $vetdat = FileGetTime("\\" & $line & "\C$\Program Files\CA\SharedComponents\ScanEngine\vet.dat", 0)
    If @error = 0 Then
        $yyyymd1 = $vetdat[0] & "/" & $vetdat[1] & "/" & $vetdat[2]
        MsgBox(0, "" & $line & " Vet.dat date", $yyyymd1,)
    EndIf
WEndoÝ÷ Ûú®¢×©äʯz¼¦¹ÈwÜp¢¹,Á«)ºÛbaxÞ®º+

Share this post


Link to post
Share on other sites
SadBunny

All is ok now?


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
bdorminy

All is ok now?

Working good. A little slow, but for my purposes I think it'll be fine. I remember reading something about the FileOpen and FileRead being the slow way and that there is a faster way but I think this is going to work out fine. Thanks for your help.

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.