Jump to content

Something not right in loop


Recommended Posts

I took this script from the helpfile and modified it a bit. Apparently I am missing something. It is supposed to parse through a list of computer names and if the c$ share is reachable, use psexec to remove an application. It's hitting the first machine, logging it as a failure (as it should since that PC is not online) then halting. It never moves on to the next in the list. I have a feeling it has to do with my If Not FileExists but not sure how to fix it. If you have a suggestion to streamline this a bit that would be appreciated too.

$file = FileOpen("c:\temp\remove.txt", 0)
$success = FileOpen("c:\temp\success.txt", 1)
$fail = FileOpen("c:\temp\fail.txt", 1)

; Check if files opened for reading/writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open List file.")
    Exit
EndIf

If $success = -1 Then
    MsgBox(0, "Error", "Unable to open Success log.")
    Exit
EndIf

If $fail = -1 Then
    MsgBox(0, "Error", "Unable to open Failure log.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    ; If c$ share is not there, write name to fail log and move on
    If Not FileExists("\\" & $line & "\c$") Then
        FileWriteLine($fail, $line)
        ExitLoop
    EndIf
    ; Send remove command and write name to success log
    RunWait("psexec -s -d \\" & $line & " MsiExec.exe /x{7C1F10C7-751F-4398-8AF5-D5C3F4512C21} /qn")
    FileWriteLine($success, $line)
WEnd

FileClose($file)
Edited by ksmith247

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

... I have a feeling it has to do with my If Not FileExists but not sure how to fix it. If you have a suggestion to streamline this a bit that would be appreciated too.

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    ; If c$ share is not there, write name to fail log and move on
    If Not FileExists("\\" & $line & "\c$") Then
        FileWriteLine($fail, $line)
        ExitLoop
    EndIf
    ; Send remove command and write name to success log
    RunWait("psexec -s -d \\" & $line & " MsiExec.exe /x{7C1F10C7-751F-4398-8AF5-D5C3F4512C21} /qn")
    FileWriteLine($success, $line)
WEnd

FileClose($file)
You've got an ExitLoop in right after it writes the error log for the 'active' machine check. Since the first machine returns an (expected) error in your case, it would fail on the first machine, write to the error log, then exit the loop - thus not moving on to the next line.

I'd say take out that ExitLoop in the IF statement and test it again.

Edit: removed extraneous code to reference only the relative text

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Would that not in turn run the following line no matter what? Would I not get an entry in the fail log and the success log?

RunWait("psexec -s -d \\" & $line & " MsiExec.exe /x{7C1F10C7-751F-4398-8AF5-D5C3F4512C21} /qn")
    FileWriteLine($success, $line)

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Actually that is what happens. The script moves on to the next in the list but always runs those two lines.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

I would like to take this opportunity to say... I am a ;) moron! :)

Can you say ELSE boys and girls? I knew you could!

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Can you say ELSE boys and girls?

You caught it before I checked back on the post. :)

Happy coding ;)

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

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...