2011-11-30 96 views

回答

11

可以使用CMD命令啓用網絡發現

netsh firewall set service type = upnp mode = mode 

然後給該命令的參數來代碼

public void ExecuteCommandSync(object command) 
{ 
    try 
    { 
    // 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; 
    proc.Start(); 
    // Get the output into a string 
    string result = proc.StandardOutput.ReadToEnd(); 
    // Display the command output. 
    Console.WriteLine(result); 
    } 
    catch (Exception objException) 
    { 
    // Log the exception 
    } 
} 

如果該命令不工作找到另一個命令啓用網絡發現acording到您的系統。

+2

謝謝,我也發現「netsh advfirewall防火牆」這也是有用的:http://support.microsoft.com/kb/947709 – fxam

+1

netsh防火牆折舊,因爲Fxam指出netsh advfirewall防火牆是替代品,所以你可以傳遞如下命令:「netsh advfirewall firewall set rule group = \」Network Discovery \「new enable = Yes」 –

相關問題