MAPPORT – Simple alternative to NET USE for Citrix COM and LPT Ports

I posted this internally first but have realized that it has value outside Citrix as well.

Surprise. Citrix could support more than COM9 for its COM port redirection.

Currently Citrix recommends using NET USE to map COM ports. The problem is that NET USE has a feature (bug?) that only allows up to COM9. This is because as soon as you try COM10, it mistakenly thinks that COM10 is the remote name. There must be parsing in NET USE that only allows for a one digit suffix. Besides this, NET USE is really only meant for LPT ports anyways.

So, why not build our own version of NET USE? Good question. Here’s the answer:

// MAPPORT.cpp : Simple Program to map COM and LPT ports
//

#include "stdafx.h"


int wmain(int argc, WCHAR* argv[])
{
    if(argc == 3)
    {
        DWORD rc;
        NETRESOURCE NetResource;

        memset(&NetResource, 0, sizeof(NetResource));

        NetResource.dwType          = RESOURCETYPE_PRINT;
        NetResource.lpLocalName     = argv[1];
        NetResource.lpRemoteName    = argv[2];

        wprintf(L"Mapping Local(%s) to Remote(%s)\n", argv[1], argv[2]);

        // we want a added connection with nothing special
        rc = WNetAddConnection2(&NetResource, NULL, NULL, 0);

        if(rc != NO_ERROR)
        {
            wprintf(L"Error with WNetAddConnection2 rc(0x%x, %u)\n", rc, rc);
        }
        else
        {
            wprintf(L"Mapped successfully\n");
        }

    }
    else
    {
        wprintf(L"MAPPORT local_device remote_device");
    }

	return 0;
}

This is a simple tool I wrote just for the sake of testing. It turns out to be very handy for this issue (>COM9). There is a tool that Citrix has provided internally called MAPCOMPORT (Internal Article CTX109186) but I believe you can only get it if your are a reseller. This tool was created in 2006 based on the problem with greater than 9 COM ports.
If there is interest, I am willing to look into providing this code in executable form. I realize that not everyone has Visual Studio installed. I do not think that it is common within Citrix blogs to provide executables. It will be interesting to see how this would work.

About

Live near Brisbane, Australia. Software developer currently focused on iOS and Android. Avid Google Local Guide

Posted in COM Port Redirection, PortICA
5 comments on “MAPPORT – Simple alternative to NET USE for Citrix COM and LPT Ports
  1. Jose Manuel Santos says:

    Hi Jeff,

    Have you alredy created the exe version? I would to test this because we’re having problems with wyse thin clients and COM port redirection. The issue is that sometimes the port maps, sometimes not. We’re currently using the net use method, and we believe that alternative methods could be a chance for us.

    Thanks in advance,

    Jose.

  2. jeffreymuir says:

    I have a ZIP but no way to distribute it. At this point I’m a bit stuck. The only known way to provide content that I know of is through the Citrix developer’s site.

    I’ll see if I can find a way to get this out there.

    Jeff

    • Nikolaj says:

      I tried the ctxcommap but i am getting a runtime error on xenapp 4.5 win2003.
      If you are still reading this thread – can you email me the zip file with an exe i could test with ?
      Thank you in advance

  3. I would love to get a Executable version of your wonderful script, my current job has a RFID reader we are attempting to get to work via citrix but it wants to use com16, and came to a road block.

    I dont know of a way to mass distrubute this but citrix might be interested in your script if you provied proven testing?

    Kevin

  4. Check out the CTXCOMMAP utility at the Ctrl-Alt-Del IT Consultancy website at http://www.ctrl-alt-del.com.au/CAD_TSUtils.htm.

    It does what you want.

    *****************************************************************************************************

    CTXCOMMAP is a command-line tool to enable a user to map serial ports beyond COM9: in a Citrix Server Session.

    This utility was written to respond to public requests to address the limitations of the NET USE command found in the MS Windows Operating System.

    NET USE is limited in being able to map COM ports beyond COM9:. In a Citrix Server environment, it is sometimes required to map ports greater than COM9:. This Utility was written to function in Citrix environments ONLY.

Comments are closed.

Archives
Categories
Follow Red Circle Blog on WordPress.com
%d bloggers like this: