谁做过控制服务器的COM+啊? 我都找了好久了!可以控制FTP 虚拟空间等操作的 以下转自网上 Option ExplicitPrivate Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _ (ByVal lpBuffer As String, ByVal nSize As Long) As LongPublic Function CreateFTPDirectory(ByVal VirtrueName As String, ByVal LocalPath As String) As Boolean Dim ExistFTP As Boolean Dim ServerObj As Object Dim VirtrueDirObj As Object Dim MyVirtrueDir As Object
ExistFTP = False CreateFTPDirectory = False
On Error GoTo ErrFTP If CheckExistIIS Then Set ServerObj = GetObject("IIS://LocalHost/MSFTPSVC/1/ROOT") For Each MyVirtrueDir In ServerObj If UCase(MyVirtrueDir.Class) = UCase("IIsFtpVirtualDir") Then If UCase(MyVirtrueDir.Name) = UCase(Trim(VirtrueName)) Then ExistFTP = True End If End If Next
If ExistFTP Then Set VirtrueDirObj = ServerObj.GetObject("IIsFtpVirtualDir", VirtrueName) Else Set VirtrueDirObj = ServerObj.Create("IIsFtpVirtualDir", VirtrueName) End If
VirtrueDirObj.Path = LocalPath VirtrueDirObj.AccessRead = True VirtrueDirObj.AccessWrite = True VirtrueDirObj.SetInfo Set ServerObj = Nothing Set VirtrueDirObj = Nothing End If CreateFTPDirectory = True Exit Function
ErrFTP: Call WriteLog("clsServer", "CreateFTPDirectory", Err.Description) MsgBox "Error: " & Err.Description, vbCritical, "Create FTP Directory Error" Err.Clear End FunctionPublic Function DeleteFTPDirectory(ByVal VirtrueName As String) As Boolean Dim ServerObj As Object Dim MyVirtrueDir As Object
DeleteFTPDirectory = False
On Error GoTo ErrFTP If CheckExistIIS Then Set ServerObj = GetObject("IIS://LocalHost/MSFTPSVC/1/ROOT") For Each MyVirtrueDir In ServerObj If UCase(MyVirtrueDir.Class) = UCase("IIsFtpVirtualDir") Then If UCase(MyVirtrueDir.Name) = UCase(Trim(VirtrueName)) Then ServerObj.Delete "IIsObject", VirtrueName End If End If Next Set ServerObj = Nothing End If DeleteFTPDirectory = True Exit FunctionErrFTP: Call WriteLog("clsServer", "DeleteFTPDirectory", Err.Description) MsgBox "Error: " & Err.Description, vbCritical, "Delete FTP Directory Error" Err.Clear End FunctionPrivate Function CheckExistIIS() As Boolean Dim SysDir As String, IISStartPath As String Dim FTP As Object, WWW As Object
On Error GoTo CheckErr
Set WWW = GetObject("IIS://LocalHost/W3SVC") Set FTP = GetObject("IIS://LocalHost/MSFTPSVC") If Not (IsObject(FTP) And IsObject(WWW)) Then MsgBox "Not exist the service of WEB.", vbInformation, "Information" CheckExistIIS = False Else SysDir = Space(127) GetSystemDirectory SysDir, Len(SysDir) SysDir = Left(SysDir, InStr(1, SysDir, Chr(0)) - 1) IISStartPath = SysDir & "\iisreset.exe /start" If Shell(IISStartPath, vbHide) = 0 Then CheckExistIIS = False MsgBox "Can not start the service." Else CheckExistIIS = True End If End If Set FTP = Nothing Set WWW = Nothing Exit Function
CheckErr: Call WriteLog("clsServer", "CheckExistIIS", Err.Description) MsgBox Err.Description CheckExistIIS = False Err.Clear End Function
设置虚拟目录 Public Function WebVirtualDir(ByVal strWebSite As String, ByVal strFriendlyName As String, ByVal strWebPath As String, ByVal strDefaultDoc As String) As Boolean Dim objADSI As Object Dim objWebVDir As Object On Error GoTo Lib_Err Set objADSI = GetObject("IIS://LocalHost/W3SVC/1/Root") Set objWebVDir = objADSI.Create("IIsWebVirtualDir", strWebSite) objWebVDir.SetInfo Set objWebVDir = objADSI.GetObject("IIsWebVirtualDir", strWebSite) objWebVDir.AppCreate True objWebVDir.Put "AppFriendlyName", strFriendlyName objWebVDir.Put "AppRoot", "/LM/W3SVC/1/Root/" & strWebSite objWebVDir.Put "Path", strWebPath objWebVDir.Put "AppIsolated", 0 objWebVDir.Put "DefaultDoc", strDefaultDoc objWebVDir.Put "AccessFlags", 535 objWebVDir.SetInfo WebVirtualDir = True Lib_End: Set objWebVDir = Nothing Set objADSI = Nothing Exit Function Lib_Err: WebVirtualDir = False strError = Err.Description Err.Clear Resume Lib_End End FunctionPrivate Sub Command1_Click() Call WebVirtualDir("aa", "aa", "E:\Web", "Default.asp") End Sub
以下转自网上
Option ExplicitPrivate Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As LongPublic Function CreateFTPDirectory(ByVal VirtrueName As String, ByVal LocalPath As String) As Boolean
Dim ExistFTP As Boolean
Dim ServerObj As Object
Dim VirtrueDirObj As Object
Dim MyVirtrueDir As Object
ExistFTP = False
CreateFTPDirectory = False
On Error GoTo ErrFTP
If CheckExistIIS Then
Set ServerObj = GetObject("IIS://LocalHost/MSFTPSVC/1/ROOT")
For Each MyVirtrueDir In ServerObj
If UCase(MyVirtrueDir.Class) = UCase("IIsFtpVirtualDir") Then
If UCase(MyVirtrueDir.Name) = UCase(Trim(VirtrueName)) Then
ExistFTP = True
End If
End If
Next
If ExistFTP Then
Set VirtrueDirObj = ServerObj.GetObject("IIsFtpVirtualDir", VirtrueName)
Else
Set VirtrueDirObj = ServerObj.Create("IIsFtpVirtualDir", VirtrueName)
End If
VirtrueDirObj.Path = LocalPath
VirtrueDirObj.AccessRead = True
VirtrueDirObj.AccessWrite = True
VirtrueDirObj.SetInfo
Set ServerObj = Nothing
Set VirtrueDirObj = Nothing
End If
CreateFTPDirectory = True
Exit Function
ErrFTP:
Call WriteLog("clsServer", "CreateFTPDirectory", Err.Description)
MsgBox "Error: " & Err.Description, vbCritical, "Create FTP Directory Error"
Err.Clear
End FunctionPublic Function DeleteFTPDirectory(ByVal VirtrueName As String) As Boolean
Dim ServerObj As Object
Dim MyVirtrueDir As Object
DeleteFTPDirectory = False
On Error GoTo ErrFTP
If CheckExistIIS Then
Set ServerObj = GetObject("IIS://LocalHost/MSFTPSVC/1/ROOT")
For Each MyVirtrueDir In ServerObj
If UCase(MyVirtrueDir.Class) = UCase("IIsFtpVirtualDir") Then
If UCase(MyVirtrueDir.Name) = UCase(Trim(VirtrueName)) Then
ServerObj.Delete "IIsObject", VirtrueName
End If
End If
Next
Set ServerObj = Nothing
End If
DeleteFTPDirectory = True
Exit FunctionErrFTP:
Call WriteLog("clsServer", "DeleteFTPDirectory", Err.Description)
MsgBox "Error: " & Err.Description, vbCritical, "Delete FTP Directory Error"
Err.Clear
End FunctionPrivate Function CheckExistIIS() As Boolean
Dim SysDir As String, IISStartPath As String
Dim FTP As Object, WWW As Object
On Error GoTo CheckErr
Set WWW = GetObject("IIS://LocalHost/W3SVC")
Set FTP = GetObject("IIS://LocalHost/MSFTPSVC")
If Not (IsObject(FTP) And IsObject(WWW)) Then
MsgBox "Not exist the service of WEB.", vbInformation, "Information"
CheckExistIIS = False
Else
SysDir = Space(127)
GetSystemDirectory SysDir, Len(SysDir)
SysDir = Left(SysDir, InStr(1, SysDir, Chr(0)) - 1)
IISStartPath = SysDir & "\iisreset.exe /start"
If Shell(IISStartPath, vbHide) = 0 Then
CheckExistIIS = False
MsgBox "Can not start the service."
Else
CheckExistIIS = True
End If
End If
Set FTP = Nothing
Set WWW = Nothing
Exit Function
CheckErr:
Call WriteLog("clsServer", "CheckExistIIS", Err.Description)
MsgBox Err.Description
CheckExistIIS = False
Err.Clear
End Function
Public Function WebVirtualDir(ByVal strWebSite As String, ByVal strFriendlyName As String, ByVal strWebPath As String, ByVal strDefaultDoc As String) As Boolean
Dim objADSI As Object
Dim objWebVDir As Object
On Error GoTo Lib_Err
Set objADSI = GetObject("IIS://LocalHost/W3SVC/1/Root")
Set objWebVDir = objADSI.Create("IIsWebVirtualDir", strWebSite)
objWebVDir.SetInfo
Set objWebVDir = objADSI.GetObject("IIsWebVirtualDir", strWebSite)
objWebVDir.AppCreate True
objWebVDir.Put "AppFriendlyName", strFriendlyName
objWebVDir.Put "AppRoot", "/LM/W3SVC/1/Root/" & strWebSite
objWebVDir.Put "Path", strWebPath
objWebVDir.Put "AppIsolated", 0
objWebVDir.Put "DefaultDoc", strDefaultDoc
objWebVDir.Put "AccessFlags", 535
objWebVDir.SetInfo
WebVirtualDir = True
Lib_End:
Set objWebVDir = Nothing
Set objADSI = Nothing
Exit Function
Lib_Err:
WebVirtualDir = False
strError = Err.Description
Err.Clear
Resume Lib_End
End FunctionPrivate Sub Command1_Click()
Call WebVirtualDir("aa", "aa", "E:\Web", "Default.asp")
End Sub
'Active DS Type Library
'Active DS IIS Extension Dll
'Active DS IIS Namespace Provider