I didn't know it before, and I still couldn't find relevant information on the Internet. Later I accidentally saw the relevant content in a delphi introduction, so I used vb as an imitation.
If some people accidentally see the benefits, they are very pleased.
Basic: Add the following references: 1, iisext. dll; 2, adsiis. dll; 3, activeds. tlb.
1. Create a virtual directory in IIS,
Dim sComputer as string
Dim websvc, vRoot, vDir
SComputer = "localhost"
'Get Default Web Site Object
Set websvc = GetObject ("IIS: //" & sComputer & "/W3svc/1 ")
'Get root of Default Web Site
Set vRoot = websvc. GetObject ("IIsWebVirtualDir", "Root ")
Dim itm As ListItem
Dim buf As String, errInfo As String, tryVirt
For Each itm In ListView1.ListItems
Err. Clear
On Error Resume Next
Set tryVirt = GetObject ("IIS: //" & sComputer & "/W3svc/1/ROOT/" & itm. SubItems (1 ))
'Debug. Print Err. Number
'If no virtual directory is available, an error occurs. You can create a new virtual directory.
If Err. Number <> 0 Then
Err. Clear
Set vDir = vRoot. Create ("IISWebVirtualDir", itm. SubItems (1 ))
VDir. path = itm. Text
VDir. Accessread = True
VDir. SetInfo
Else
'Record The Name Of The created virtual directory.
'If tryVirt. AppGetStatus2 = 0 Then
ErrInfo = errInfo & vbCrLf & itm. SubItems (1)
End If
Next
Actually
Set websvc = GetObject ("IIS: //" & sComputer & "/W3svc/1 ")
Set vRoot = websvc. GetObject ("IIsWebVirtualDir", "Root ")
Set vDir = vRoot. Create ("IISWebVirtualDir", vdName)
VDir. Path = someDir
VDir. setInfo
These statements are enough.
2. Delete virtual directory
Dim sComputer, sPhyDir, sVirDir As String