windowsbatch-filegoogle-cloud-platformvirtual-machineguacamole

Shutdown Windows When Remote Desktop Connection Closes


I am trying to build a "desktop in the cloud" using the Apache Guacamole service and Google Cloud VMs. I have accepted that I can not boot a VM on a RDP connection, but I am wondering if there is a way to shut down a machine on RDP disconnect.

I have a Windows Datacenter VM hosted as my "desktop" and Apache Guacamole hosted on another server to RDP into the desktop. To save money I would like to shut down the VM when I disconnect. Basically, when I terminate the RDP connection can I detect that and trigger shutdown?

I am not averse to writing bash or python scripts to accomplish this task, but I need some direction.

Thanks, Owen


Solution

  • As per Squashman's recommendation:

    I created a task in the Task Scheduler that is triggered by a disconnect from the user and had it run a bash script to shutdown the machine.

    Thank you!

    Script:

    SHUTDOWN /p