WCF自主服务,安装程序类和netsh
发布时间:2020-12-13 20:14:33 所属栏目:Windows 来源:网络整理
导读:我有一个自主的WCF服务应用程序,我想通过一个msi安装程序包部署.端点使用http端口8888.为了在安装后在 Windows 2008上启动项目,我必须以管理员身份运行该程序,或者必须使用netsh编辑http设置: "netsh http add urlacl url=http://+:8888/ user=Everyone"
我有一个自主的WCF服务应用程序,我想通过一个msi安装程序包部署.端点使用http端口8888.为了在安装后在
Windows 2008上启动项目,我必须以管理员身份运行该程序,或者必须使用netsh编辑http设置:
"netsh http add urlacl url=http://+:8888/ user=Everyone" 我想从我的安装程序类编辑http设置.因此,我从Install()方法调用以下方法: public void ModifyHttpSettings() { string parameter = @"http add urlacl url=http://+:8888/ user=Everyone"; System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("netsh",parameter); psi.Verb = "runas"; psi.RedirectStandardOutput = false; psi.CreateNoWindow = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; psi.UseShellExecute = false; System.Diagnostics.Process.Start(psi); } 此方法适用于英文版本的Windows,但不适用于本地化版本(群组Everyone在本地化版本中具有不同的名称).我也试图使用Environment.UserName来允许至少访问当前登录的用户.但是这也不行,因为安装程序类由在用户SYSTEM下运行的msi服务运行.因此Enviroment.UserName返回SYSTEM,这不是我想要的.有没有办法向msi安装程序类的所有(或至少为当前登录的)用户授予对我自己的主机WCF服务的访问权限?
我的解决方案:
public void ModifyHttpSettings() { string everyone = new System.Security.Principal.SecurityIdentifier( "S-1-1-0").Translate(typeof(System.Security.Principal.NTAccount)).ToString(); string parameter = @"http add urlacl url=http://+:8888/ user=" + everyone; ProcessStartInfo psi = new ProcessStartInfo("netsh",parameter); psi.Verb = "runas"; psi.RedirectStandardOutput = false; psi.CreateNoWindow = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.UseShellExecute = false; Process.Start(psi); } SID“S-1-1-0”是一个众所周知的SID,代表“Everyone”帐户. Windows的所有本地化版本都相同.方法Translate of SecurityIdentifier类返回Everyone帐户的本地化名称. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows 10 Mail应用程序上订阅的日历?
- windows-server-2012 – 有没有办法同时更改多台服务器上的
- .net – WPF,Windows窗体或其他?
- windows-phone-7 – 一个ListBox里面的WP7 TextBlock没有包
- windows – 从Delphi中以编程方式检查数字签名
- Windows命令提示符下的git help
- windows – 自动计算机库存建议
- ScrollViewer中的WebView带有XAML元素头
- wix – 一个MSI中的两个PathEdit对话框(错误2343 – 指定的
- windows-server-2012 – Windows Server 2012 Branchcache与
推荐文章
站长推荐
热点阅读