Question

I currently have a HttpListener Webserver implemented that serves my current log, that exists in a richTextBox, as a HTML page. This way I can check the status of the application from anywhere on the network.
There are a couple issues with this implementation, it requires admin privileges to run the netsh command to make it connectable. However admin privileges are not really available in a ClickOnce application. I would like to keep using ClickOnce for deployment, so is there another alternative that will not require admin privileges?
Is this possible using sockets?
I would like to keep it as simple as possible as I do not to really support SET or POST, etc.

Was it helpful?

Solution

Hey dude just paste the following code in your application what it will do is if your application does not have admin privileges then it will force application restart in admin mode obviously it will ask first!

public static bool IsAdmin()
        {
            WindowsIdentity id = WindowsIdentity.GetCurrent();
            WindowsPrincipal p = new WindowsPrincipal(id);
            return p.IsInRole(WindowsBuiltInRole.Administrator);
        }

public static void AqquireAdminMode()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.WorkingDirectory = Environment.CurrentDirectory;
            startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
            startInfo.Verb = "runas";
            try
            {
                Process p = Process.Start(startInfo);
            }
            catch (System.ComponentModel.Win32Exception ex)
            {



       return;
        }

        System.Windows.Forms.Application.Exit();
    }

and this code should be called in form load event

if(!IsAdmin())
{
  AqquireAdminMode();
} 

feel free to ask if you still face problems!

OTHER TIPS

You are using HttpListener and i think that TcpListener could be a alternative for this if you can upload your code then it is possible to illustrate the working of TcpListener

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top