Skip to content

A Microsoft RDP Client (MSTSC) Plugin to Report Device Battery Life

Notifications You must be signed in to change notification settings

Field-Effect-LLC/RDP-BattMon

Repository files navigation

BattMon: An Add-In to Microsoft's Remote Desktop Client to Report Device Battery Life

What is this application?

This is a Remote Desktop Add-in (for MSTSC.exe), that will allow you to report your laptop/tablet/device battery life to the terminal server.

Why would I want this?

If you like to work full screen on a remote desktop connection, but you work from a laptop or other battery powered device, you won't have to exit full screen every time you want to check your battery life.

How do I install it?

Please check the Releases page for binary files, or build from source using Visual Studio 2017.

On the Remote Desktop Client Side

In the future, I plan to make installation easier for less technical users. For the time being, you need to install the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default\AddIns\BattMon

Note regedit.exe must be run as a standard user, not as an administrator, or mstsc will not detect the key when it is run as a standard user.

Then, add a string value to the BattMon Key:

"Name"="C:\\path\\to\\your\\folder\\RDS_Client_Addin_BattMon.dll"

Alternatively, you can create a Windows registry file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default\AddIns\BattMon]
"Name"="C:\\path\\to\\your\\folder\\RDS_Client_Addin_BattMon.dll"

On the Remote Desktop Server Side

You need to run the RDS_Server_TrayApp_BattMon.exe application on the Remote Desktop side. When it's running, you should see a battery icon on your Remote Desktop's taskbar:

taskbar_screenshot

Screenshot

server_battery

Troubleshooting

By default, logs are stored in %APPDATA%\BattMon\Log.txt, but they need to be enabled before starting.

Enable Logging on the Client Side

The client won't begin logging until there is a file called log4net.config in the same folder as your client-side DLL. Create a new text file with that name, and paste this code into it.

Then, change this line:

    <level value="INFO" />

to this:

    <level value="DEBUG" />

Once that's done, you can connect to the server using your Remote Desktop client.

Enable Logging on the Server Side

On the server side, you need a configuration file that has the same name as your EXE, with the file extension .config. So, if you're EXE's name is RDS_Server_TrayApp_BattMon.exe, create a new text file called RDS_Server_TrayApp_BattMon.exe.config, and paste this code in it.

Then, change this line:

    <level value="INFO" />

to this:

    <level value="DEBUG" />

Once that's done, you can start the EXE.

Roadmap

Here's my desired roadmap:

  1. Proof-of-concept (complete)
  2. Improve server-side battery reporting application (complete)
    1. Pass client name to server, so app can display the client's name (complete)
    2. Make the app display as a tray icon, instead of a Windows form, to display the battery level, just as the native battery icon would (complete)
  3. Allow multiple batteries to be reported upon (complete)
    1. Right now, it just reports on the first battery it finds. I don't know how common multiple batteries are, though, so this is low priority unless otherwise determined. (complete)
  4. Create a client-side installer to automatically add the registry entry.

🎵 "BattMon... da-na-na-na-na-na-na-na"

I know 😉

Credit

All credit for Remote Desktop Virtual Channels communication goes to: https://www.codeproject.com/Articles/16374/How-to-Write-a-Terminal-Services-Add-in-in-Pure-C