Elsinore

User Forum

www.screenconnect.com
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Command line to join an unattended session as Host
JeffBower
#1 Posted : Wednesday, May 18, 2011 6:34:39 PM
Rank: Member
Joined: 5/14/2010
Posts: 17
Location: Chicago
Hi-

I need a command line to join (as Host) an established unattended session. What I am trying to do is integrate with Dell Kase, which allows me to add a command line to an action/button. I would have approximately 150 machines/unattended sessions, which would identify via IP. Is this possible and, if so, how?

Thanks!
Jeff
Jake Morgan
#2 Posted : Friday, May 20, 2011 2:28:15 AM
Rank: Administration
Joined: 4/9/2010
Posts: 859
I'm not familiar with Dell Kace. It sounds like a rich client app if it's running a command line. Still, it would probably be best to launch internet explorer with a URL of a page on your ScreenConnect installation. Have you setup the unattended sessions yet? Can you tag them with something useful to connect with, or will you need to go beyond the tag to find the sessions by IP?
Jake Morgan
#3 Posted : Thursday, May 26, 2011 9:01:13 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
Here is a page that you can put in your ScreenConnect directory that will redirect to launch the host:

Code:
<%@ WebHandler Language="C#" Class="LaunchHostClient" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Elsinore.ScreenConnect;

public class LaunchHostClient : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var sessionTag = context.Request.QueryString["Tag"];
        var relayUri = ServerExtensions.GetRelayUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, true);

        using (var sessionManager = ServerExtensions.SessionManagerChannelFactory.CreateChannel())
        {
            var sessionSummary = sessionManager.GetSessionSummaries("All Machines", new Dictionary<string, string>(), null).First(ss => string.Equals(ss.Tag, sessionTag, StringComparison.InvariantCultureIgnoreCase));

            var clp = new ClientLaunchParameters();
            clp.Host = relayUri.Host;
            clp.Port = relayUri.Port;
            clp.SessionID = sessionSummary.SessionID;
            clp.ProcessType = ProcessType.Host;
            clp.EncryptionKey = ServerCryptoManager.Instance.PublicKey;
            clp.AccessToken = ServerCryptoManager.Instance.GetAccessToken(clp.SessionID, clp.ProcessType);
            clp.ApplicationTitle = Resources.Default.Client_ApplicationTitle;
            clp.SessionTitle = sessionSummary.Tag;

            var url = "Bin/Elsinore.ScreenConnect.HostClient.application" + ClientLaunchParameters.ToQueryString(clp);
            context.Response.AppendHeader("Refresh", "0; URL=" + url);        
            
            // does the right thing with the browser, but reports the wrong query string    
            //context.Response.Redirect(url);
        }
    }

    public bool IsReusable { get { return false; } }
}


It takes a parameter "Tag" and will connect to the session with that tag.

From the command line:

Code:
"iexplore.exe" "http://localhost:8040/LaunchHostClient.ashx?Tag=DURHAM"


It works, but leaves up the IE window.





This method gets never uses IE and should work, but doesn't like any redirects:

Code:
rundll32 dfshim.dll,ShOpenVerbApplication "http://localhost:8040/LaunchHostClient.ashx?Tag=DURHAM"


Also uncommenting the redirect line up in the code should work and use IE, but then the wrong activation URI is reported to the clickonce app. So we have to do a client redirect (appendheader) rather than a server redirect (response.redirect). The problem here is that it leaves up the IE window.

Really the optimal solution would be for you to have a script file that did a wget of the LaunchHostClient.ashx, then ran the results with rundll32.
File Attachment(s):
LaunchHostClient.ashx (2kb) downloaded 25 time(s).
Jake Morgan
#4 Posted : Thursday, May 26, 2011 11:01:50 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
Oh, and along with the rambling from above. Let me present the disclaimer that the above code only works with 2.2.1600 or greater ... which isn't even available yet. Hoping to get it out soon through.
Jake Morgan
#5 Posted : Thursday, June 16, 2011 3:32:35 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
Try this, to use with wget/curl:

Code:
<%@ WebHandler Language="C#" Class="LaunchHostClient" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Elsinore.ScreenConnect;

public class LaunchHostClient : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var sessionTag = context.Request.QueryString["Tag"];
        var relayUri = ServerExtensions.GetRelayUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, true);

        using (var sessionManager = ServerExtensions.SessionManagerChannelFactory.CreateChannel())
        {
            var sessionSummary = sessionManager.GetSessionSummaries("All Machines", new Dictionary<string, string>(), null).First(ss => string.Equals(ss.Tag, sessionTag, StringComparison.InvariantCultureIgnoreCase));

            var clp = new ClientLaunchParameters();
            clp.Host = relayUri.Host;
            clp.Port = relayUri.Port;
            clp.SessionID = sessionSummary.SessionID;
            clp.ProcessType = ProcessType.Host;
            clp.EncryptionKey = ServerCryptoManager.Instance.PublicKey;
            clp.AccessToken = ServerCryptoManager.Instance.GetAccessToken(clp.SessionID, clp.ProcessType);
            clp.ApplicationTitle = Resources.Default.Client_ApplicationTitle;
            clp.SessionTitle = sessionSummary.Tag;

            var url = new Uri(context.Request.Url, "Bin/Elsinore.ScreenConnect.HostClient.application" + ClientLaunchParameters.ToQueryString(clp));
            context.Response.Write(url);

        }
    }

    public bool IsReusable { get { return false; } }
}
File Attachment(s):
LaunchHostClient.ashx (2kb) downloaded 21 time(s).
Jake Morgan
#6 Posted : Thursday, June 16, 2011 3:47:06 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
This needs to change:

Code:
context.Response.Write(url);


To this:

Code:
context.Response.Write(url.OriginalString);
Jake Morgan
#7 Posted : Thursday, June 16, 2011 3:50:20 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
Here is a launch.cmd file that will launch with rundll32 rather than involving IE:

Code:
for /f %%A IN ('curl.exe http://%1:%2/LaunchHostClient.ashx?Tag^=%3') DO SET URL=%%A
rundll32 dfshim.dll,ShOpenVerbApplication %URL:&=^&%


To launch from command line:

Code:
launch.cmd support.myserver.com 8040 MYPCNAME


And you'll need curl.exe in the directory. I've attached my version of curl, but I can't vouch for it's authenticity.
File Attachment(s):
curl.exe (391kb) downloaded 44 time(s).
launch.cmd (1kb) downloaded 25 time(s).
bradcccs
#8 Posted : Sunday, October 09, 2011 2:09:58 AM
Rank: Newbie
Joined: 10/9/2011
Posts: 1
Hey Jake,

Thanks for your efforts on the LaunchHostClient concept - has been a great addition to our arsenal.

We are currently calling via IE and thus end up with a lot of "dead IE windows".
(edit: Should mention that calling via IE is indeed working but just leaves the windows open as mentioned)

Having no luck converting over to CURL.

Version = 2.3.1918.4269


Variation on the context.Response that we are using:
Code:

context.Response.AppendHeader("Refresh", "0; URL=" + url.AbsoluteUri);


The CURL progress window shows no progress (0's) and thus the rundll request does not receive relevant info and is generated as
Code:

rundll32 dfshim.dll,ShOpenVerbApplication &=^&



The resultant log reports that the "URI is empty"

Code:

ERROR DETAILS
    Following errors were detected during this operation.
    * [9/10/2011 11:59:00 AM] System.UriFormatException
        - Invalid URI: The URI is empty.
        - Source: System
        - Stack trace:
            at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
            at System.Uri..ctor(String uriString)
            at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)



Am I upsetting the apple cart using the "AppendHeader" response?

I am by no means an expert on this subject so any assistance is appreciated. Remains as the last piece to the puzzle before we switch 100% to the SC solution for our remote support needs.

Cheers

Brad
Jake Morgan
#9 Posted : Saturday, October 15, 2011 10:55:34 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
You'll want to Response.Write the URL from your handler rather than send it as a header. If you response.write it, curl will get the output and you should be set.
nkayoumi
#10 Posted : Wednesday, December 14, 2011 4:48:42 PM
Rank: Member
Joined: 12/1/2011
Posts: 20
I created the ashx and it launches the host client successfully. But it works only if I'm logged-on to the site. If I'm not logged-on, it launches a user logon window. I read someplace on the forums that the host client can be launched without authentication but one has to pass a token to it. Where do I specify the token in the code above?

Thanks
nkayoumi
#11 Posted : Wednesday, December 14, 2011 6:07:20 PM
Rank: Member
Joined: 12/1/2011
Posts: 20
OK, I see in the LaunchHostClient.ashx that we specify the access token:

Code:
clp.AccessToken = ServerCryptoManager.Instance.GetAccessToken(clp.SessionID, clp.ProcessType, "System");


But I'm still getting the "A user name and password is being requested.." logon window. if I'm not logged on to the web site.

How do I by-pass the authentication completely?
Jake Morgan
#12 Posted : Wednesday, December 14, 2011 10:36:11 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
What does your handler file look like?

If there is any line about asserting a permission or anything, remove it.
nkayoumi
#13 Posted : Thursday, December 15, 2011 9:14:44 PM
Rank: Member
Joined: 12/1/2011
Posts: 20
Thanks. Removing the assert permission fixed the problem! Now when I call the handler from firefox, it launches the host client without a problem. But I get a blank page on IE and host client doesn't get launched.

Launching it from curl give me this error:

Quote:
* Activation of http://remote.test.com/LaunchHostClient.ashx resulted in exception. Following failure messages were detected:
+ Exception reading manifest from http://remote.test.com/LaunchHostClient.ashx: the manifest may not be valid or the file could not be opened.
+ Root element is missing.


Here is my handler code:

Code:

<%@ WebHandler Language="C#" Class="LaunchHostClient" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Elsinore.ScreenConnect;

public class LaunchHostClient : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var sessionTag = context.Request.QueryString["Tag"];
        var relayUri = ServerExtensions.GetRelayUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, true);

        using (var sessionManager = Elsinore.ScreenConnect.ServiceChannelPool<Elsinore.ScreenConnect.ISessionManagerChannel>.Instance.Borrow())
        {
            var sessionSummary = sessionManager.GetSessionSummaries("All Machines", new Dictionary<string, string>(), null).First(ss => string.Equals(ss.Tag, sessionTag, StringComparison.InvariantCultureIgnoreCase));

            var clp = new ClientLaunchParameters();
            clp.Host = relayUri.Host;
            clp.Port = relayUri.Port;
            clp.SessionID = sessionSummary.SessionID;
            clp.ProcessType = ProcessType.Host;
            clp.EncryptionKey = ServerCryptoManager.Instance.PublicKey;
            clp.AccessToken = ServerCryptoManager.Instance.GetAccessToken(clp.SessionID, clp.ProcessType, "Administrator");
            clp.ApplicationTitle = Resources.Default.Client_ApplicationTitle;
            clp.SessionTitle = sessionSummary.Tag;

            var url = new Uri(context.Request.Url, "Bin/Elsinore.ScreenConnect.HostClient.application" + ClientLaunchParameters.ToQueryString(clp));           
            //context.Response.Write(url);
            //context.Response.AppendHeader("Refresh", "0; URL=" + url.AbsoluteUri);
            context.Response.Write(url.OriginalString);
            //context.Response.Write(url.AbsoluteUri);

        }
    }

    public bool IsReusable { get { return false; } }
}


I've tried all the different combination of "Response.Write" as shown commented out in the code snippet and had no luck.
nkayoumi
#14 Posted : Monday, December 19, 2011 8:16:27 PM
Rank: Member
Joined: 12/1/2011
Posts: 20
Is this a bug in the software? Anyone?
Jake Morgan
#15 Posted : Monday, December 19, 2011 9:31:11 PM
Rank: Administration
Joined: 4/9/2010
Posts: 859
How are you using CURL? You need to use CURL to get the URL, then call rundll32 to run the result:

Code:
for /f %%A IN ('curl.exe http://%1:%2/LaunchHostClient.ashx?Tag^=%3') DO SET URL=%%A
rundll32 dfshim.dll,ShOpenVerbApplication %URL:&=^&%

nkayoumi
#16 Posted : Tuesday, December 20, 2011 10:37:03 PM
Rank: Member
Joined: 12/1/2011
Posts: 20
I'm using it exactly like the example above, both the handler and launch.cmd. It's just not working. I have windows 7 64bit. I don't know if that makes a difference.

richy240
#17 Posted : Wednesday, May 09, 2012 8:39:17 PM
Rank: Newbie
Joined: 5/7/2012
Posts: 5
Location: Houston, TX
This isn't working for me, although I think it would be a great start to Kace integration. The error I get is Compiler Error Message: CS0117: 'Elsinore.ScreenConnect.ServerExtensions' does not contain a definition for 'SessionManagerChannelFactory'. I have not yet attempted the curl method... One of the reasons I like the "direct" method of using a URL is that it will work in browsers that aren't IE since it's just opening a URL and not actually launching an application.

I should mention that I am not a developer, so a lot of this is Greek to me. Thank you for any help you can provide.
Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.