用.net (在IIS中)创建虚拟目录(包括 脚本语言)

iis|创建|脚本|虚拟目录

两种语言在IIS中创建虚拟目录

用.net在IIS中创建虚拟目录
使用.NET的目录服务就可以访问IIS的设置,添加虚拟目录其实就是创建一个DirectoryEntry
复杂的在于DirectoryEntry的属性,其实就是虚拟目的一些配置,比如,权限,是否要log,应用程序名等
Properties非常多,而且文档不太好找
详细可以参考MSDN以下内容
help://MS.MSDNQTR.2004JUL.1033/iissdk/iis/configuring_properties_in_the_iis_user_interface.htm

代码示例:

   const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";

   DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
   DirectoryEntry entry = new DirectoryEntry(constIISWebSiteRoot + "/" + virtualDirName);

   DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");

   //must be end with a '\'
   tbEntry.Properties["Path"][0] = virtualDirPath;
   tbEntry.Invoke("AppCreate",true);
   tbEntry.Properties["AccessRead"][0] = true;
   tbEntry.Properties["ContentIndexed"][0] = false;
   tbEntry.Properties["DefaultDoc"][0] = "index.asp";
   tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
   tbEntry.Properties["AppIsolated"][0] = 2;
   tbEntry.Properties["AccessScript"][0] = true;   
   tbEntry.Properties["DontLog"][0] = true;   
   
   tbEntry.CommitChanges();

//************************************************************
用windows 脚本语言创建虚拟目录.

Set shell = Wscript.CreateObject( "WScript.Shell" )

If Wscript.Arguments.Count < 2 Then
usage = "USAGE: theVbs virtual_directory_name directory_location_to_map"
WScript.Echo usage
Wscript.Quit
End If

vDirName = Wscript.Arguments(0)
vDirPath = Wscript.Arguments(1)

' Get the name of the current directory
Set fso = WScript.CreateObject( "Scripting.FileSystemObject" )
vDirPath = fso.GetFolder( vDirPath ).Path

' Does this IIS application already exist in the metabase?
On Error Resume Next
Set objIIS = GetObject( "IIS://localhost/W3SVC/1/Root/" & vDirName )
If Err.Number = 0 Then
result = shell.Popup( "A virtual directory named " & vDirName & " already exists. " & vbCrLf & vbCrLf & "Would you like it re-mapped for this sample?", 0 ,"Remap Virtual Directory?", 4 + 32 )' 4 = YesNo & 32 = Question
If result = 6 Then ' 6 = Yes
DeleteVirtualDirectory vDirName
Else
WScript.Quit
End If
End If

'Using IIS Administration object , turn on script/execute permissions and define the virtual directory as an 'in-process application.
Set objIIS = GetObject( "IIS://localhost/W3SVC/1/Root" )
Set vDirObj = objIIS.Create( "IISWebVirtualDir", vDirName )

vDirObj.Path = vDirPath
vDirObj.AuthNTLM = True
vDirObj.AccessRead = True
vDirObj.AccessWrite = True
vDirObj.AccessScript = True
vDirObj.AccessExecute = True
vDirObj.AuthAnonymous = True
'vDirObj.AnonymousUserName = owner
vDirObj.AnonymousPasswordSync = True
vDirObj.AppCreate True
vDirObj.SetInfo

If Err.Number > 0 Then
shell.Popup Err.Description, 0, "Error", 16 ' 16 = Stop
WScript.Quit
End If

' Get the name of the account for the anonymous user in IIS
owner = vDirObj.AnonymousUserName

' Change necessary folder permissions using CACLS.exe
aclCmd = "cmd /c echo y| CACLS "
aclCmd = aclCmd & """" & vDirPath & """"
aclCmd = aclCmd & " /E /G " & owner & ":C"
rtc = shell.Run( aclCmd , 0, True )

aclCmd = "cmd /c echo y| CACLS "
aclCmd = aclCmd & """" & vDirPath & """"
aclCmd = aclCmd & " /E /G ""VS Developers"":C"
rtc = shell.Run( aclCmd , 0, True )

If Err.Number > 0 Then
shell.Popup Err.Description, 0, "Error", 16 ' 16 = Stop
WScript.Quit
Else
res = vDirName & " has been created at" & vbCrLf & vDirPath
shell.Popup res, 0, "All done", 64 ' 64 = Information
End If

Sub DeleteVirtualDirectory( NameOfVdir )

Set iis = GetObject("IIS://localhost/W3SVC/1/Root")
iis.Delete "IISWebVirtualDir", vDirName

If Err.Number <> 0 Then

errorString = "Unable to delete exisiting virtual directory."

If Err.Description Is Nothing Then
errorString = errorString & "Error Code: " & Err.Number
Else
errorString = errorString & "Description: " & Err.Description
End If

shell.Popup errorString, 0, "Error", 16 ' 16 = Stop
End If

End Sub

//********************  end

时间: 2024-11-08 19:00:38

用.net (在IIS中)创建虚拟目录(包括 脚本语言)的相关文章

ASP.NET对IIS中的虚拟目录进行操作

asp.net|iis|虚拟目录 ASP.NET对IIS中的虚拟目录进行操作 //假如虚拟目录名为"Webtest",先在项目中引用 //System.DirectoryServices.dll,再 using System.DirectoryServices; protected System.DirectoryServices.DirectoryEntry dirroot; 1.添加新的虚拟目录 DirectoryEntry newVirDir = dirroot.Children

用ADSI编程实现IIS中建立虚拟目录

conn.asp不再贴出.这里从数据库中读出目录名 <!--#include file="conn.asp"--><%'response.end  '//这是做调试时用的on error resume nextSet Rs=Server.CreateObject("ADODB.Recordset")Rs.ActiveConnection = MyConnectionSql="select * from 你的表名 where 你指定的条件&

ASP.NET操作IIS中的虚拟目录

asp.net|iis|虚拟目录     在做系统开发的过程中,我们经常会遇到用asp.net来操作IIS,如新建虚拟目录.更改虚拟目录的属性.删除虚拟目录等操作,现在分析如下://假如虚拟目录名为"Webtest",先在项目中引用 //System.DirectoryServices.dll,再 using System.DirectoryServices; protected System.DirectoryServices.DirectoryEntry dirroot; 1.添加

用ASP.NET对IIS中的虚拟目录进行操作

asp.net|iis|虚拟目录 在做系统开发的过程中,我们经常会遇到用asp.net来操作IIS,如新建虚拟目录.更改虚拟目录的属性.删除虚拟目录等操作,现在分析如下://假如虚拟目录名为"Webtest",先在项目中引用    //System.DirectoryServices.dll using  System.DirectoryServices;  protected  System.DirectoryServices.DirectoryEntry  dirroot;   1

ASP.NET对IIS中的虚拟目录进行操作的代码_实用技巧

复制代码 代码如下: //假如虚拟目录名为"Webtest",先在项目中引用 //System.DirectoryServices.dll,再 using System.DirectoryServices; protected System.DirectoryServices.DirectoryEntry dirroot; 1.添加新的虚拟目录 复制代码 代码如下: DirectoryEntry newVirDir = dirroot.Children.Add("Webtes

C# 操作iis创建虚拟目录与虚拟路径方法

在.Net中我们可以使用内置的类DirectoryEntry来承载IIS服务器中的任何网站,虚拟路径或应用程序池对象,例如:   DirectoryEntry ent = new DirectoryEntry("IIS://localhost/w3svc/1/root"): 就创建了一个IIS路径为IIS://localhost/w3svc/1/root的虚拟路径对象.   为了在IIS中创建一个网站,我们首先需要确定输入的网站路径在IIS中是否存在,这里主要是根据网站在IIS中的 S

用vbs控制iis创建虚拟目录

参照了InetpubAdminScriptsadsutil.vbs写的创建虚拟目录的脚本:'////////////////////////// begin //////////////////////////////////////////On Error Resume NextstrVirtualDirectoryName = InputBox("请输入虚拟目录名")If strVirtualDirectoryName = "" Then msgbox(&quo

iisvdir.vbs iis虚拟目录管理脚本使用介绍_vbs

IIS管理器也是通过调用iisvdir.vbs来实现虚拟目录的创建和删除的.我们可以通过命令行的方式来执行iisvdir.vbs脚本 1)创建虚拟目录: cscript c:\windows\system32\iisvdir.vbs [/s server] [/u username /p password] /create [virtualRoot] Alias PhysicalPath 2)删除虚拟目录: 1cscript c:\windows\system32\iisvdir.vbs [/s

请高手指点如何使用installshield11.5创建虚拟目录部属asp.net2.0开发的网站?

问题描述 使用asp.net2.0开发的站点,想打包自动安装到IIS的默认网站下的某个目录中,可以新建一个目录,但不另建一个新的站点放到下面,如何实现?请跟贴者说的详细一些,能解决问题,一知半解并不能解决什么问题者请勿发言,多谢大家,多谢高手发言 解决方案 解决方案二:我就是不懂!!!!为什么不给我发???帮你顶北!!!不然沉下去!解决方案三:is11.5的自动配置数据库已经搞懂了,在IIS中加入虚拟目录的方法,请高手指点,细致的指点,在默认网站下加入某个目录放入开发的站点,使用户进行浏览,请高