DNS管理有了初步的成功迹象。。:)

在网上找了好久的资料,都是VBScript的。唯一看到的就是用C#却无法创建的代码。。
使用的是System.Management
代码如下:
ManagementClass dnsRRClass = new ManagementClass(@"\\ServerNameHere\root\MicrosoftDNS", "MicrosoftDNS_ResourceRecord", null);
ManagementBaseObject inParams = dnsRRClass.GetMethodParameters("CreateInstanceFromTextRepresentation");
inParams["DnsServerName"] = sServer;
inParams["ContainerName"] = sDomainName;
inParams["TextRepresentation"] = sTextRepresentation;
ManagementBaseObject outParams = dnsRRClass.InvokeMethod("CreateInstanceFromTextRepresentation", inParams, null);
Console.WriteLine("Executing the method returns {0}", outParams["ReturnValue"]);

原始地址:http://www.gotdotnet.com/community/messageboard/Thread.aspx?id=31217

看了这么久,有个发现。。System.Management
,WMI其实就是把Com组件WbemScripting.SWbemLocator封装起来罢了。所以连WMI出错的提示都是ComException....   teeth_smile.gif

既然如此,为了兼容性,我还不如干脆使用WbemScripting.SWbemLocator好了。。tongue_smile.gif

使用下面的代码可以成功加入一条A纪录。

  WbemScripting.SWbemMethod method = objRR.Methods_.Item("CreateInstanceFromTextRepresentation",0);
  WbemScripting.SWbemObject inparam = method.InParameters;
  inparam.Properties_.Add("DnsServerName",WbemScripting.WbemCimtypeEnum.wbemCimtypeString,false,0);
  inparam.Properties_.Add("ContainerName",WbemScripting.WbemCimtypeEnum.wbemCimtypeString,false,0);
  inparam.Properties_.Add("TextRepresentation",WbemScripting.WbemCimtypeEnum.wbemCimtypeString,false,0);
  inparam.Properties_.Item("DnsServerName",0).set_Value(ref server);
  inparam.Properties_.Item("ContainerName",0).set_Value(ref strDomain);
  inparam.Properties_.Item("TextRepresentation",0).set_Value(ref strRR);

  objRR.ExecMethod_("CreateInstanceFromTextRepresentation",inparam,0,null);

不过离成功的路还很远,只是实现了一个功能,心里有点高兴,上来发泄一下。dudu莫见怪哈。。wink_smile.gif

posted on 2004-04-12 10:45 嘻哈呵嘿 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/skyover/archive/2004/04/12/5833.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值