修改的时候可以使用 System.XML.xmlDoc提供的方法!
获取计算机名称用 System.Messaging 下面的 有一个什么 GetMachineId 不知道可不可以!
干脆 Localhost 算了。

解决方案 »

  1.   

    修改倒不是问题,关键是怎样在安装的时候,得到WEB.CONFIG这个文件?
    先谢了!!!
      

  2.   

    Public Overrides Sub Install(ByVal stateSaver As _
    System.Collections.IDictionary)
       ' Gets the parameter passed across in the CustomActionData.
       Dim installlog As New System.IO.StreamWriter("Installation.log")
       installlog.AutoFlush = True
       Try
          Dim ProvidedName As String = _
    Me.Context.Parameters.Item("ServerName")
          Dim SvcName As String = Me.Context.Parameters.Item("ServiceName")
          
          installlog.WriteLine("Starting Edit of the config file")      If ProvidedName = "" Or SvcName = "" Then
             Throw New InstallException("No arguments specified")
          End If      ' Uses reflection to find the location of the config file.
          Dim Asm As System.Reflection.Assembly = _
    System.Reflection.Assembly.GetExecutingAssembly
          Dim strConfigLoc As String
          strConfigLoc = Asm.Location      Dim strTemp As String
          strTemp = strConfigLoc
          strTemp = strTemp.Remove(strTemp.LastIndexOf("\"), Len(strTemp) _
    – strTemp.LastIndexOf("\"))
          strTemp = strTemp.Remove(strTemp.LastIndexOf("\"), Len(strTemp) _
    – strTemp.LastIndexOf("\"))      Dim FileInfo As System.IO.FileInfo = New _
    System.IO.FileInfo(strTemp & "\web.config")      installlog.WriteLine("File info: " & strTemp)      If Not FileInfo.Exists Then
             Throw New InstallException("Missing config file")
          End If      ' Loads the config file into the XML DOM.
          Dim XmlDocument As New System.Xml.XmlDocument()
          XmlDocument.Load(FileInfo.FullName)      ' Finds the right node and change it to the new value.
          Dim Node As System.Xml.XmlNode
          Dim FoundIt As Boolean = False
          For Each Node In 
             XmlDocument.Item("configuration").Item("appSettings")
             ' Skips any comments.
             If Node.Name = "add" Then
                If Node.Attributes.GetNamedItem("key").Value = _
    "appname.servername.service" Then
                   ' Note that "Service1.asmx" should be replaced with the
                   ' actual name of the XML Web service file.
                   Node.Attributes.GetNamedItem("value").Value = _
    "http://" & ProvidedName & "/" & SvcName & "/Service1.asmx"
                   FoundIt = True
                End If
             End If
          Next Node      If Not FoundIt Then
             Throw New InstallException("Config file did not contain a _
    ServerName section")
             End If         ' Writes out the new config file.
             XmlDocument.Save(FileInfo.FullName)   Finally
          installlog.WriteLine("Ending edit of config file")
          installlog.Close()
       End TryEnd Sub