HttpListener
HTTP リクエストをリッスンするために使用する C# アプリケーションを作成しました。私が使用する名前空間プレフィックスは、現在のユーザーを使用netsh
して登録されています(SOの全員が提案したように)。
問題は、netsh を使用しているにもかかわらず、アプリケーションが管理者以外のユーザーに対して「アクセスが拒否されました」という例外をスローすることです。OSはWindows7です。
netsh
更新:管理者以外のユーザーでアプリケーションを実行すると、アプリケーションがコマンドを実行していないように見えます。コードに問題はありますか? スローされる例外はありません。
AddAddress("http://localhost:8400/", Environment.UserDomainName, Environment.UserName);
HttpListener _listener = new HttpListener();
_listener.Prefixes.Add("http://localhost:8400/");
_listener.Start();
...
/** method stolen from an SO thread. sorry can't remember the author **/
static void AddAddress(string address, string domain, string user)
{
string args = string.Format(@"http add urlacl url={0}", address) + " user=\"" + domain + "\\" + user + "\"";
ProcessStartInfo psi = new ProcessStartInfo("netsh", args);
psi.Verb = "runas";
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = true;
Process.Start(psi).WaitForExit();
}