How to programmatically turn on “Network Discovery” in Windows OS?

My project open ports using UPnP protocol. Windows disables UPnP device discovery by default, one needs to turn on Network Discovery in Network and Sharing Center to enable UPnP device discovery.

Is there a way to do this programatically?


You can use cmd command for enable network discovery

netsh firewall set service type = upnp mode = mode

then give that command as parameter to code

public void ExecuteCommandSync(object command)
    // create the ProcessStartInfo using "cmd" as the program to be run,
    // and "/c " as the parameters.
    // Incidentally, /c tells cmd that we want it to execute the command that follows,
    // and then exit.
    System.Diagnostics.ProcessStartInfo procStartInfo =
      new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

    // The following commands are needed to redirect the standard output.
    // This means that it will be redirected to the Process.StandardOutput StreamReader.
    procStartInfo.RedirectStandardOutput = true;
    procStartInfo.UseShellExecute = false;
    // Do not create the black window.
    procStartInfo.CreateNoWindow = true;
    // Now we create a process, assign its ProcessStartInfo and start it
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo = procStartInfo;
    // Get the output into a string
    string result = proc.StandardOutput.ReadToEnd();
    // Display the command output.
  catch (Exception objException)
    // Log the exception

If that command doesnt work find another command to enable network discovery acording to your system.

Need Your Help

How to recompute styles of an element in firefox extension

jquery css firefox-addon xul

In my firefox extension, When creating an element, All the styles got applied correctly. But when I alter its content using jquery, $('#blahblah').html(responseText), It loses all its styles, but s...

how to get value of a node where a leaf is dropped in a tree

drag-and-drop tree extjs4 treenode

I have a tree panel where a leaf can be dropped to a node. I want to get the value of that node where the leaf is dropped.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.