Skip to content

Latest commit

 

History

History
99 lines (85 loc) · 4.75 KB

README-windows.md

File metadata and controls

99 lines (85 loc) · 4.75 KB

Windows dependencies/limitations

  • Requires Windows 10 Pro (the Home version lacks some of the tools needed, like query user), at least version 2004
  • Requires PowerShell at least version 5.1
PS C:\WINDOWS\system32> $psversiontable.psversion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      18362  1171
PS C:\WINDOWS\system32> query user
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
>user1                 console             1  Active          .  2/4/2021 11:26 AM
 user2                                     4  Disc            4  2/4/2021 12:21 PM
 user3                                     5  Disc            .  2/4/2021 12:24 PM
  • Requires (should come with windows):

    • %WINDIR%\system32\query.exe
    • %WINDIR%\system32\tsdiscon.exe
  • Users need to be local (not microsoft accounts)

  • Username can have spaces, but needs to be shorter than 22 characters (apparently local windows accounts are limited to 20)

  • Requires you to enable executing privileged unsigned PowerShell scripts (as Administrator! - warning!): https:/go.microsoft.com/fwlink/?LinkID=135170. These are needed to run the ps1 scripts to grab window name, display notification and take screenshot. Run this in a PowerShell ran as Administrator

 Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine

Manual installation

  • Install python3 (e.g. via choco install python3 pip)

  • From an Administrator PowerShell run:

pip install paho-mqtt pyYaml wmi
  • Either unzip the project's files or use git clone to copy it to C:\Program Files\mqttNanny (as Administrator)

  • Edit configuration at C:\Program Files\mqttNanny\mqttNanny.yaml

  • Test - run manually via a Privileged PowerShell:

cd "c:\Program Files\mqttNanny"
python mqttNanny.py
  • Run as a system service (via Privileged PowerShell)
    choco install nssm
    
    • Configure the mqttNanny service (sadly, we need to use PROGRA~1 to avoid spaces)
    nssm install mqttNanny "C:\Python39\python.exe" "C:\Progra~1\mqttNanny\mqttNanny.py"
    nssm set mqttNanny AppDirectory "c:\Progra~1\mqttNanny"
    # optional, for debugging
    nssm set mqttNanny AppStdout 'C:\Program Files\mqttNanny\mqttNanny-daemon-stdout.txt'
    nssm set mqttNanny AppStderr 'C:\Program Files\mqttNanny\mqttNanny-daemon-stderr.txt'
    nssm start mqttNanny
    

Note, that if using AppStdout, AppStderr, the logs are not rotate and will continue to grow...

  • Set up Task Scheduler for each account to export some info (see next section)

Task Scheduler

Individual users can run a periodic task via Task Scheduler to:

  • export current application name
  • snap screenshot on demand
  • receive notifications

Start Task Scheduler (as each user) -> Create Task ->

  • General:
    • Name: mqttNanny-$username
    • Run only when user is logged on
  • Triggers:
    • New -> Begin a task At logon
    • Specific User
    • Repeat task every 1 minute for a duration of Indefinitely
    • Enabled
  • Actions:
    • New -> Start a program
    • Program/script -> C:\Windows\System32\wscript.exe
    • Add arguments (optional): "C:\Program Files\mqttNanny\windowsControl\mqttNannyTaskLauncher.vbs"
    • NOTE: The arguments must contain the quotes, otherwise it will be interpreted as two arguments!
  • Conditions:
    • Power - uncheck Start the task only if computer is on AC power
  • Settings:
    • Uncheck Stop the task if it runs longer than

Next, log out and back in to the account, to start the task.

Caveats

  • Because of how query user command reports active users you have the following situation. When the computer is in the logon screen (that displays a fullscreen image) and the user list is not visible, then the system thinks the screensaver is on and doesn't tick down time. If instead, you are at the logon screen, ready to enter a password (for any user), even if you haven't entered the password, the system will report the currently selected user as active (and screensaver will be marked as off). Thankfully windows will revert to the picture logon screen after ~30s of inactivity, so it shouldn't waste too much time...
  • The code hardcodes the "C:\Program Files" path in some places. If it's not correct for your system, please change it in:
    • mqttNannyTaskLauncher.vbs
  • The code expects that the user's %TEMP% dirs live at $USER/AppData/Local/Temp