首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows 8中的家庭安全Web过滤器

Windows 8中的家庭安全Web过滤器
EN

Stack Overflow用户
提问于 2012-07-27 07:40:27
回答 1查看 566关注 0票数 1

我正在尝试编写一些C#代码,以便以编程方式读/写Windows8中的家庭安全设置控件,特别是网络和应用程序筛选器列表。

WMI可以使用如下命令公开这些值:

代码语言:javascript
复制
PS C:\Windows\system32> Get-WmiObject -Class WpcURLOverride -Namespace root/CIMV2/Applications/WindowsParentalControls

__GENUS          : 2
__CLASS          : WpcURLOverride
__SUPERCLASS     :
__DYNASTY        : WpcURLOverride
__RELPATH        : WpcURLOverride.SID="S-1-5-21-4241459202-2635765079-3956675256-1002",URL="http://block.com"
__PROPERTY_COUNT : 3
__DERIVATION     : {}
__SERVER         : TEST-BOX
__NAMESPACE      : root\CIMV2\Applications\WindowsParentalControls
__PATH           : \\TEST-BOX\root\CIMV2\Applications\WindowsParentalControls:WpcURLOverride.SID="S-1-5-21-4241459202-2
                   635765079-3956675256-1002",URL="http://block.com"
Allowed          : 2
SID              : S-1-5-21-4241459202-2635765079-3956675256-1002
URL              : http://block.com
PSComputerName   : TEST-BOX

__GENUS          : 2
__CLASS          : WpcURLOverride
__SUPERCLASS     :
__DYNASTY        : WpcURLOverride
__RELPATH        : WpcURLOverride.SID="S-1-5-21-4241459202-2635765079-3956675256-1002",URL="http://allow.com"
__PROPERTY_COUNT : 3
__DERIVATION     : {}
__SERVER         : TEST-BOX
__NAMESPACE      : root\CIMV2\Applications\WindowsParentalControls
__PATH           : \\TEST-BOX\root\CIMV2\Applications\WindowsParentalControls:WpcURLOverride.SID="S-1-5-21-4241459202-2
                   635765079-3956675256-1002",URL="http://allow.com"
Allowed          : 1
SID              : S-1-5-21-4241459202-2635765079-3956675256-1002
URL              : http://allow.com
PSComputerName   : TEST-BOX

This question提到了复制现有的对象,但我还没有找到一种方法来实现泛型或这些特定的WMI对象。

如何插入或删除条目?感谢您的意见。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-13 02:12:28

张贴一个可行的,如果不是理想的,完整性的答案。这些代码片段适用于我的用例,但希望它们能帮助某些人

代码语言:javascript
复制
  private static SecurityIdentifier UserSID(string username)
  {
     var f = new NTAccount(username);
     return (SecurityIdentifier)f.Translate(typeof(SecurityIdentifier));
  }


  private string PsCmdAddSite(Uri url, bool allow)
  {
     return string.Format(
@"$o = ([WMIClass] ""root\CIMV2\Applications\WindowsParentalControls:WpcURLOverride"").CreateInstance()
$o.Allowed = {0}
$o.URL = ""{1}""
$o.SID = ""{2}""
$o.Put()", (allow ? "1" : "2"), url, UserSID('TargetUsername'));
  }


  private static string PsCmdRemoveAllSites()
  {
     return
@"$allSites = Get-WmiObject -Class WpcURLOverride -Namespace root/CIMV2/Applications/WindowsParentalControls;
foreach ($site in $allSites){Remove-WmiObject -InputObject $site;}";
  }


  private static void RunPsScript( string scriptText )
  {
     // create Powershell runspace, logically a single PS session
     Runspace runspace = RunspaceFactory.CreateRunspace();
     runspace.Open();

     // create a pipeline and feed the script text
     Pipeline pipeline = runspace.CreatePipeline();
     pipeline.Commands.AddScript(scriptText);

     pipeline.Commands.Add("Out-String");

     // execute the script
     pipeline.Invoke();
     runspace.Close();
  }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11679607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档