我用asp.net中操作IIS是编写IISVDir.dll操作IIS
使用方法:
Dim test As New IISVDir()
test.CreateVirtualDir("localhost","vdir","e:\","test")
注意:
1、web目录中的test必需存在
2、当此代码用于web中时,出错为不能创建Active组件,
修改“x:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config”中的<processModel 键修改为userName="SYSTEM" password="AutoGenerate"就能解决.
iisvpath.vb代码
Imports System
Imports ActiveDs
Imports Microsoft.VisualBasic
Namespace iisvpath
Public Class IISVPath
REM 创建FTP目录
'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 = GetObject("IIS://" & ComputerName & "/MSFTPSVC/1/Root")
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
本文地址:http://com.8s8s.com/it/it45361.htm