none
Difficulty working with workflow RRS feed

  • Pergunta

  • First of all, thank you for your willingness to help me.

    I created a script that tests my connection to a game server and it works perfectly. But I want to add a feature. I want every 100 ping done, in the background the script will average the ping (milliseconds) of the connection and determine if the connection is good or not. And if the connection is not good, the script opens a popup saying I should not play.

    I created the workflow, but I'm confused. I do not know what to do so that every 100 ping the script perform a test of the quality of the connection to the server. Below I leave the characteristics of my system and the code.

    Thank you for helping me!


    SPECIFICATIONS OF MY SYSTEM:
    Windows 10 PRO - Version 10.0.14393
    PowerShell 5.1.14393.479

    CODE:

    #Teste de estabilidade (Stability test)
    workflow estabilidade {
        $matriz = @()
        $soma = 0
        $rst = 0
        while ($matriz.count -lt 11) {
            $matriz = ((Test-Connection $ip -Count 1 -ErrorAction Ignore).responseTime) + 4
        }
        
        foreach ($i in $matriz) {$soma += $i}
        $rst = $soma / $matriz.count
    
        if ($rst -lt 31) {return 0}
        elseif ($rst -gt 31 -and $rst -lt 71) {return 1}
        elseif ($rst -gt 71 -and $rst -lt 120) {return 2}
        else {return 3}
    }
    
    #Personalização (Customization)
    function personaliza {
        if (!$psISE) {
            $janela = $host.ui.rawui
    
            $janela.WindowTitle = "LOLping"
            $janela.ForegroundColor = 3
            $janela.BackgroundColor = 0
    
            $tela = $janela.windowsize
            $tela.height = 52
            $tela.width = 25
            $janela.windowsize = $tela
        }
        clear-host
    }
    
    #Principal (main)
    Clear-Host
    Write-Host ((' ' * 7) + 'Versão 1.0' + (' ' * 7))
    personaliza
    
    $msg = New-Object -com wscript.shell
    $ip="8.23.25.177"
    
    while ($true){
    	$hora = get-date -UFormat “%H:%M:%S”
    
        try {
            $ms = ((Test-Connection $ip -Count 1 -ErrorAction Stop).responseTime) + 4
            
            if ($ms -lt 100) {
    		    write-host "$hora ─►  $ms ms  █"
    	    }
    	    
            else {
    		    write-host "$hora ─►  $ms ms  █" -ForegroundColor Red
    		    write-output "$hora ─►  $ms ms" >> "$home\NetLog.log"
    	    }
        }
    
        catch {
            write-host "$hora ─►  FALHA" -ForegroundColor Red
        }
    
    	Start-Sleep 1
    }


    sábado, 10 de dezembro de 2016 20:17

Todas as Respostas