int AccessFlags = 1;
                if (CheckScript.Checked) { AccessFlags += 512; }
                if (CheckIsapi.Checked) { AccessFlags += 4; }
                if (CheckWrite.Checked) { AccessFlags += 16; }                RootSiteEntry = new DirectoryEntry("IIS://localhost/W3SVC");
                
                NewSiteEntry = RootSiteEntry.Children.Add(SiteNumber.ToString(), "IIsWebServer");
                NewSiteEntry.CommitChanges();
                //设置站点IP地址、端口、主机头
                NewSiteEntry.Properties["ServerBindings"].Value = SiteIp.Text.Replace("(全部未分配)","") + ":" + SitePort.Text.ToString() + ":" + SiteHostName.ToString();
                //设置站点名称
                NewSiteEntry.Properties["ServerComment"].Value = SiteName.Text;
                //设置站点的访问权限
                NewSiteEntry.Properties["AccessFlags"].Value = AccessFlags;
                NewSiteEntry.CommitChanges();
----------------------------------------
这个是我的代码
------------错误信息-------------------------
未处理 System.Runtime.InteropServices.COMException
  Message="当文件已存在时,无法创建该文件。 (异常来自 HRESULT:0x800700B7)"
  Source="System.DirectoryServices"
  ErrorCode=-2147024713
  StackTrace:
       在 System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsContainer.Create(String className, String relativeName)
       在 System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName)
       在 ServerTools.Index.button2_Click(Object sender, EventArgs e) 位置 d:\servertools\ServerTools\ServerTools\Index.cs:行号 57
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 ServerTools.Program.Main() 位置 d:\servertools\ServerTools\ServerTools\Program.cs:行号 17
       在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()