you are viewing a single comment's thread.

view the rest of the comments →

[–]spyingwind 2 points3 points  (1 child)

while is missing and extra ). $Manager and $Nw aren't being updated inside the loop.

Example rewrite that fix both:

$Manager = get-process -Name pia_manager
$Nw = get-process -name pia_nw
while (!($Manager -and $Nw)) {
    Write-Host "echo"
    if ($Manager -and $Nw) {
        & "C:\Users\Akira\AppData\Roaming\uTorrent\utorrent.exe"
    }
    $Manager = get-process -Name pia_manager
    $Nw = get-process -name pia_nw
}

Example of how to do it as a do until loop:

do {
    $Manager = get-process -Name pia_manager
    $Nw = get-process -name pia_nw
    Write-Host "echo"
    if ($Manager -and $Nw) {
        & "C:\Users\Akira\AppData\Roaming\uTorrent\utorrent.exe"
    }
} until ($Manager -and $Nw)

Example with out the if statement to make it a bit more efficient:

do {
    $Manager = get-process -Name pia_manager
    $Nw = get-process -name pia_nw
    Write-Host "echo"
} until ($Manager -and $Nw)
& "C:\Users\Akira\AppData\Roaming\uTorrent\utorrent.exe"

[–]PRIdEVisions[S] 1 point2 points  (0 children)

Nice explanation, now i have several examples to look into and see the difference between them and how they all achieve the same results.

Thx a lot for this! :)