Jump to content

automatyzacja, harmonogram zadan


Recommended Posts

Posted

Witam , chialbym stworzyc taka mala automatyzacje mianowicie jak wylacze z paska zadan bt to chcialbym zeby zatrzymaly sie wszystkie uslugi zwiazane z bt a jest ich kilkai nie chxe zeby dzialaly w tle jak juz przestane uzywac bt myslalem zrobic to w ten sposob

Po wylaczeniu bt harmonogram zadan wyzwalacz i tu kod  z zdarzen jak wylaczone odpala skrypt powershel i by zatrzymywal ale mam maly problem bo o ile jak wlaczam bt pojawia sie kod 18 bthserv to juz przy wylaczaniu nic sie nie pojawia ktos ma pomysl jak to obejsc?

Posted
Cytat

# MonitorBluetooth.ps1

# Funkcja do sprawdzania, czy Bluetooth jest włączony i używany
function Is-BluetoothEnabledAndInUse {
    # Sprawdź, czy Bluetooth jest włączony
    $btStatus = Get-Service -Name bthserv | Select-Object -ExpandProperty Status
    if ($btStatus -ne 'Running') {
        return $false
    }

    # Sprawdź, czy są aktywne urządzenia Bluetooth
    $btDevices = Get-PnpDevice -Class Bluetooth | Where-Object { $_.Status -eq 'OK' }
    return $btDevices.Count -gt 0
}

# Główna pętla monitorująca
while ($true) {
    # Odczekaj 30 minut
    Start-Sleep -Seconds 10

    # Sprawdź, czy Bluetooth jest włączony i używany
    if (-not (Is-BluetoothEnabledAndInUse)) {
        Write-Host "Bluetooth jest wyłączony. Zatrzymuję usługi."
        Stop-Service -Name BluetoothUserService -Force -ErrorAction Stop
        Stop-Service -Name BTAGService -Force -ErrorAction Stop
        Stop-Service -Name bthserv -Force -ErrorAction Stop
        Stop-Service -Name BthAvctpSvc -Force -ErrorAction Stop
        break
    } else {
        Write-Host "Bluetooth jest w użyciu. Czekam na wyłączenie..."
    }

    # Odczekaj dodatkowe 15 minut
    Start-Sleep -Seconds 10
}

 

Ktos zerknie? niby działą tzn jeszcze nie dodalem do harmonogramu ale recznie dziala  ale chcialbym zeby ktos sprawdzil czy jest ok.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information