none
registering HttpListener for a user

    Question

  • Need to register HttpListener so as to run the worker role in elevated permission.

    I have been setting up a small program to record details being scanned in from a barcode scanner, the program runs and works well if I am an Administrator on the PC but if I am the normal User logged in to the PC the program comes up with the following message.

    Error Message > System.Net.HttpListenerException (0x80004005): Failed to listen on prefix

    I have found out that the HttpListener must be given admin privileges before it will work, but cannot find any details on what to do to register it.

    I have included a small section from a web page were they discuss the problem but is in or for Azure and use a "csdef" file and I need this written in VB.net (2013), I am not storing it in the cloud or accessing the internet with the program. 

    RavenDB registers HTTPListener.To register HttpListener you need admin previledges. However, worker role by default does not have admin previledges.

    In order to run the worker role with admin privileges, modify the csdef file and add the following:
    <Runtime executionContext ="elevated" />
    This makes the worker role run under elevated permission and hence it is able to register httplistener.

    Sample csdef file:
    < ?xml version="1.0" encoding="utf-8"? >
    < ServiceDefinition name="WindowsAzureProject6"xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" >
      < WorkerRole name="WorkerRole1" vmsize="Small" >
        < Runtime executionContext ="elevated" />
        < Imports >

    The key take away is that if you want to register HttpListener, run the worker role in elevated permission.

    What I need to do is to find out what has to be done and where to what file etc. so as to allow the program elevated privileges so as to run?

    I hope someone may be able to supply some assistance as it urgent that I find a fix.

    P.S. I have looked in a lot of sites (including Microsoft) and have found very little on this as I am sure it would be a problem others have come up against from time to time.

    regards,

    Glenn Sharp glenn@gyzmosystems.com.au

        


    Glenn

    Saturday, March 15, 2014 12:32 AM

All replies

  • Well I used an online code converter to convert the code at this link HttpListener Class to VB.Net. Added some bogus URLs to a string array and tried the code and received an error of access denied (like you I suppose).

    So I went into the applications properties and in Application I clicked View Windows Settings. Which brings up the below .Xml document. So you should change the line beneath --> from

    <requestedExecutionLevel  level="asInvoker" uiAccess="false" />

    To

    <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

    which should make your app receive a UAC prompt when it runs. However this will require an appropriate password for the app to run if an admin user is not running it. If an admin user is running it then click yes or whatever on the UAC prompt for the app to run with admin priviliges.

    Maybe the issue is using HTTP listener. Why does that need to be used to receive information from a bar code scanner? Is the bar code scanner sending data via a wifi network or something?

    Perhaps there's a different method for retrieving data from your bar code scanner that does not require admin priviliges.

    Also Task Scheduler can be used to allow a program to launch with the highest priviliges afforded to a user. But if a user doesn't have Admin priviliges then they need an appropriate password to launch a program that requires Admin priviliges.

    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <!-- UAC Manifest Options
                If you want to change the Windows User Account Control level replace the 
                requestedExecutionLevel node with one of the following.
    
            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
    
                Specifying requestedExecutionLevel node will disable file and registry virtualization.
                If you want to utilize File and Registry Virtualization for backward 
                compatibility then delete the requestedExecutionLevel node.
            -->
            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
          </requestedPrivileges>
        </security>
      </trustInfo>
    
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
          <!-- A list of all Windows versions that this application is designed to work with. 
          Windows will automatically select the most compatible environment.-->
    
          <!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
          <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
    
          <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
          <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
    
          <!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
          <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
    
        </application>
      </compatibility>
    
      <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
      <!-- <dependency>
        <dependentAssembly>
          <assemblyIdentity
              type="win32"
              name="Microsoft.Windows.Common-Controls"
              version="6.0.0.0"
              processorArchitecture="*"
              publicKeyToken="6595b64144ccf1df"
              language="*"
            />
        </dependentAssembly>
      </dependency>-->
    
    </asmv1:assembly>


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.




    Sunday, March 16, 2014 4:20 AM
  • Thanks for the details I will try them out on our development system hopefully it will work.

    The part I do not understand is that the function is there for the networking and you can set every different part of windows via a tick box or option somewhere but you cannot setup the one part that is most important!

    By the way the scanners are hand held units and communicate back to the software running on a local computer (with only user rights) where the data gathered is decoded and printed in various reports and stored for later use.

    If you know of another way to communicate with the scanners please let me know as I am interested in trying it?

    I have also found a mention of a program called "netsh.exe", it is a Microsoft program with command line options and can set or open a port for a listener to listen on. I am going to test and try this out this morning to see if that opens the port.

    I am interested in any other ideas anyone may have as we have not solved it as yet?

    Regards,

    The Gyzmo


    Glenn

    Sunday, March 16, 2014 8:59 PM
  • Thanks for the details I will try them out on our development system hopefully it will work.

    The part I do not understand is that the function is there for the networking and you can set every different part of windows via a tick box or option somewhere but you cannot setup the one part that is most important!

    By the way the scanners are hand held units and communicate back to the software running on a local computer (with only user rights) where the data gathered is decoded and printed in various reports and stored for later use.

    If you know of another way to communicate with the scanners please let me know as I am interested in trying it?

    I have also found a mention of a program called "netsh.exe", it is a Microsoft program with command line options and can set or open a port for a listener to listen on. I am going to test and try this out this morning to see if that opens the port.

    I am interested in any other ideas anyone may have as we have not solved it as yet?

    Regards,

    The Gyzmo


    Glenn

    Well there's more information that needs to be known.

    How do the scanners communicate back to software running on local computers?

    There's various posts in this forum over time for people wanting to communicate with bar code scanners. But it seems they all do it via USB interface.

    For some reason you use an HTTP listener which almost makes it seem like the bar code scanners are on a wifi network sending data to an HTTP listner.

    So without knowing in depth details of how your bar code scanners data is retrieved then providing another method would not be appropriate.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Sunday, March 16, 2014 11:18 PM
  • Yes you are right on both counts,

    they are using a wifi network, they are hand held terminals

    With a USB scanner it is very easy to communicate with as they are emulating a keyboard so what ever is scanned is put into the field that the cursor is at, if it was a case that we could use them I would have.

    we are using the connection to communicate back to the pc running a small server program and we are displaying various web pages on the scanner or hand held terminal.

    The barcode data and web pages sent to and from the scanner are no problem as long as we are an administrator.

    Regards,

    The Gyzmo


    Glenn

    Monday, March 17, 2014 12:02 AM
  • Using Netsh on my laptop to add or remove urlacl entries via command prompt or program requires administrative priviliges. So I don't believe that will assist you either.

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, March 17, 2014 4:58 AM
  • I have found out that once you set the options under the admin rights and then log in as a user you should still have the rights as it sets it for the PC not the user logging on.

    I have not fully tried it out as yet (stuck on another project change) but will be tomorrow morning (1700 here) I am to stressed to work on it now.

    I will let you know how it goes.

    Regards,

    The Gyzmo


    Glenn

    Monday, March 17, 2014 5:43 AM