RA: Pass Workstation and Username Parameters to Offer Remote Assistance

For those of you who successfully use the shortcut for Offer Remote Assistance (ORA), you’ve probably wanted to automate it just a little more with parameters at some point or another. You may have even come across EdmSaleBoy’s Usenet Post titled “Programatically Offer Remote Assistance.” I did a few times but it didn’t do exactly what I wanted to. Though I appreciated EdmSaleBoy’s code extraction skills, I didn’t find the solution of overwriting UnsolicitedCUI.htm to be very elegant so I spent some hours looking into alternatives.

ORA is a bit of a programming pain because it requires client-side Javascript and it’s picky about what it will and will not let you do. I wanted to find a way to call ORA from a webpage and wondered how I would pass some variables to the script. The command line was not cooperating with me so I thought that perhaps I could hack together something with javascript and Microsoft.XMLHTTP but ORA denied me access. After some hackery, I discovered the joys of objSAFClassFactory.ExtraArgument.

Using objSAFClassFactory.ExtraArgument, I was able to dynamically pass the workstation name and username (note: the username MUST be in the domain\username format or it won’t work.) So now I present to you the following code, which you can save as cmdOfferRemoteAdmin.htm under the directory %windir%\pchealth\helpctr\System\.

Remote Assistance

var szArgs = objSAFClassFactory.ExtraArgument;

var i = szArgs.indexOf(c_WorkstationTag); var j = szArgs.indexOf(c_UsernameTag); g_szWorkstation = szArgs.slice(i+c_WorkstationTag.length, j); g_szUsername = szArgs.slice(j+c_UsernameTag.length);

var i = g_szUsername.indexOf(""); g_szDomainName = g_szUsername.slice(0, i); g_szUserName = g_szUsername.slice(i+1); g_szSessionId = -1;

g_oSAFRemoteDesktopConnection = objSAFClassFactory.CreateObject_RemoteDesktopConnection(); g_oSAFRemoteConnectionData = g_oSAFRemoteDesktopConnection.ConnectRemoteDesktop(g_szWorkstation);

objInc = objSAFClassFactory.CreateObject_Incident(); objInc.RCTicketEncrypted = false; objInc.RcTicket = g_oSAFRemoteConnectionData.ConnectionParms( g_szWorkstation, g_szUserName, g_szDomainName, -1, ""); var objDict = objInc.Misc; var d = new Date(); objDict.add("DtStart", Math.round(Date.parse(d)/1000)); objDict.add("DtLength", "60"); objDict.add("Status", "Active"); objDict.add("URA", 1); objFSO = new ActiveXObject("Scripting.FileSystemObject"); tempDir = objFSO.GetSpecialFolder( 2 ); szIncidentFile = tempDir + "\UnsolicitedRA" + objFSO.GetTempName(); objInc.GetXML(szIncidentFile); var oShell = new ActiveXObject("WScript.Shell"); var szRAURL = 'C:\WINDOWS\pchealth\helpctr\binaries\helpctr.exe -Mode "hcp://system/Remote Assistance/raura.xml" -url "hcp://system/Remote Assistance/Interaction/Client/RcToolscreen1.htm"' + ' -ExtraArgument "IncidentFile=' + szIncidentFile + '"'; oShell.Run( szRAURL, 1, true ); objFSO.DeleteFile( szIncidentFile ); objSAFClassFactory.close(); return; }

Once you saved the file in the proper location, you can call it by going to %windir%\PCHEALTH\HELPCTR\Binaries\HelpCtr.exe -url hcp://system/cmdOfferRemoteAdmin.htm -ExtraArgument “WORKSTATION=winxpsp2&USERNAME=testlab\chrissy”

The downside to this code is that there’s little to no error handling. If just a blank “Windows Help” page appears, you’ve done something wrong. Make sure the computer you are attempting to connect to is pingable and that the username is in the correct format (domain\user). Also, make sure you can get the regular Offer Remote Assistance to work before calling this more advanced technique. If you are having trouble with ORA, this posting may provide some help.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, holds a master's degree in Systems Engineering and is coauthor of Learn dbatools in a Month of Lunches. Chrissy is certified in SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in Security