Join the Microsoft Dynamics AX Community at https://community.dynamics.com/ax/ today!

Wednesday, January 27, 2016

User Shadowing Directly from Online Users Form

Windows 8 and Windows Server 2012 R2 brought with it the reinstatement of RDP shadowing, with significant improvements such as multiple monitor support.

Windows 8.1 / Windows Server 2012 R2 - RDS Shadowing is back!

While shadowing is a great built-in solution for remote support, having to use the Server Manager to shadow the user is less than convenient.  Using the command line opens up programmatic solutions, but the server name and session ID of the user on that server must be known.

Can we add a Shadow button directly to the Online users form instead?

The server name is just the Computer name already available on the Online users form (the computer from which the user is connected, whether it be a terminal server, virtual desktop, or physical computer), The session ID, on the other hand, is not so readily available from within AX, but it can be fetched using the QUERY command (the ID column shown below).  Since the QUERY command has a /SERVER parameter, it even works on remote computers.



It seems like we have all the needed pieces to make a working solution, so it's time to put them all together.  Start by adding a new Shadow (control) button below the grid.



To keep the clicked method simple, just call a form method named clickedShadowControl() and do the heavy lifting there.



The first task is to call the QUERY command to fetch the session ID for the user on the server (remote desktop).  We'll construct the parameter string, create a System.Diagnostics.ProcessStartInfo object, making sure to capture the standard output of the process, and then start the process to execute the command.  If it doesn't terminate after 5 seconds, terminate it to be safe and abort.



The next task is to read the output from the QUERY command and locate the user's session ID.  The first line is the header, which allows us to locate the ID column position, and then the ID itself can be fetched from the user's data on the second line.



The last task is to call the MSTSC process with the server and now available session ID as parameters.



Finally, clicking the button launches the shadowing session in a Remote Desktop Connection window.



This is a proof of concept build that illustrates the possibilities for integrating shadowing directly into the Online users form within Dynamics AX.  Exercises such as error handling and security are left to the reader.

4 comments: