用VC控制iis的属性方法

分类: VC.NET   出处:iocblog整理  更新时间:2008-11-22   添加到收藏  

author:zfive5(zidong)(文章来源 www.iocblog.net)

email :zfive5@yahoo.com.cn
 
需求
 
    用vc修改iis的属性 如设为可以匿名访问  将默认网站下的主目录路径c:inetpubwwwroot 在vc程序里面可以更改成任意路径.
 
实现
 
    看到masterz在纯vc编写控制iis属性代码的文章(url:http://topic.csdn.net/t/20030224/15/1460500.html),总感觉有些麻烦,可能是用vb两年来的缘故吧,想了一个懒人的方法:“编写vbscript脚本,vc调用scriptcontrol控件在解析脚本了。”
    还记得两年前用msscriptcontrol 解决过一个网络问题!
 
代码如下: 
void ctestdlgdlg::onbnclickedok()
{
       // todo: 在此添加控件通知处理程序代码
       //onok();
       char szbuf[1024]=""
               "function changewebpath(computer ,webname ,path ) "
               " on error resume next "
               " dim vroot,websvc, site "
               " changewebpath=-1 "
               " set websvc = getobject("iis://"&computer&"/w3svc") "
               " if (err <> 0) then exit function "
               " for each site in websvc "
               " if site.class = "iiswebserver" then "
               "   if site.servercomment = webname then "
               "     set vroot = site.getobject("iiswebvirtualdir", "root") "
               "     vroot.path = path "
               "     vroot.setinfo "
               "     changewebpath=0 "
               "     exit function "
               "    end if "
               " end if "
               " next "
              " end function ";
                    
       cstring szscript1="";
       szscript1.format("%s",szbuf);
       cstring szscript2="z5=changewebpath("127.0.0.1","默认网站","c:\") ";
       szscript1+=szscript2;
 
       m_iis.put_language("vbscript");
       m_iis.addcode(szscript1);
       variant result= m_iis.eval("z5");
       if(result.ival==0)
       {
              afxmessagebox("success");
       }
       else
       {
              afxmessagebox("fail");
       }
   
       return;
}
 
 
脚本参照c:inetpubdminscripts*.vbs编写。
 
 
总体要比纯vc编写简单的多,而且几乎同样的代码,完全可以编写出控制iis其他属性的程序!只需编写脚本!



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。