也談用在ASP.Net中操作IIS (轉)

worldblog發表於2008-01-22
也談用在ASP.Net中操作IIS (轉)[@more@]

我用中操作IIS是編寫IISVDir.dll操作IIS
使用方法:
Dim test As New IISVDir()
test.CreateVirtualDir("localhost","vdir","e:","test")
注意:
1、目錄中的test必需存在
2、當此程式碼用於web中時,出錯為不能建立Active,
修改“x:WINNT.NETv1.0.3705CONFIGmachine.config”中的iisvpath.vb程式碼

Imports System
Imports ActiveDs
Imports Microsoft.VisualBasic
Namespace iisvpath

Public Class IISVPath

  REM 建立目錄
  'ComputerName FTP名(可以為localhost)
  'DirName 要建立的虛擬目錄名
  'LinkAddr 該虛擬目錄的真實路徑
  Function CreateFTPDir(ByVal ComputerName As String, _
  ByVal DirName As String, ByVal LinkAddr As String) As Boolean
  try
  CreateFTPDir= True
  Dim WWWServer, WWWServer1 As ActiveDs.IADs
  Dim WWWVirtualDir, WWWIF As ActiveDs.IADs
  Try
  WWWIF = Get("IIS://" & ComputerName & "/MTPSVC/1/")
  Try
  WWWIF.delete("IISFtpVirtualDir", DirName)
  Catch
  End Try
  Catch
  End Try
  WWWServer1 = GetObject("IIS://" & ComputerName & "/MSFTPSVC/1")
  WWWServer = WWWServer1.GetObject("IIsFtpVirtualDir", "Root")
  WWWVirtualDir = WWWServer.Create("IISFtpVirtualDir", DirName)
  WWWVirtualDir.Path = LinkAddr
  WWWVirtualDir.AccessRead = True
  WWWVirtualDir.AccessWrite = False
  WWWVirtualDir.SetInfo()
  CreateFTPDir=true
  catch
  CreateFTPDir=false
  end try
  end function

  REM 建立虛擬目錄
  'ComputerName WEB伺服器名(可以為localhost)
  'DirName 要建立的虛擬目錄名
  'LinkAddr 該虛擬目錄的真實路徑
  'WWWSiteName 站點名稱
  Function CreateVirtualDir(ByVal ComputerName As String, _
  ByVal DirName As String, ByVal LinkAddr As String, _
  ByVal WWWSiteName As String) As Boolean
  Try
  CreateVirtualDir = True
  Dim WWWServer, WWWServer1 As ActiveDs.IADs
  Dim WWWVirtualDir, WWWIF As ActiveDs.IADs
  Try
  Try
  WWWIF = GetObject("IIS://" & ComputerName & "/W3SVC/1/Root/" & WWWSiteName)
  Try
  WWWIF.delete("IISWebVirtualDir", DirName)
  Catch
  End Try
  Catch
  End Try
  WWWServer1 = GetObject("IIS://" & ComputerName & "/W3SVC/1")
  WWWServer = WWWServer1.GetObject("IIsWebVirtualDir", "Root")
  WWWVirtualDir = WWWServer.Create("IISWebVirtualDir", WWWSiteName & "/" & DirName)
  WWWVirtualDir.Path = LinkAddr
  WWWVirtualDir.AccessRead = True
  WWWVirtualDir.AccessScript = True
  WWWVirtualDir.SetInfo()
  CreateVirtualDir = True
  Catch
  End Try
  Catch
  CreateVirtualDir = False
  End Try
  End Function

End Class

end Namespace


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-998202/,如需轉載,請註明出處,否則將追究法律責任。

相關文章