高分请教一个小问题,来者有分

weiym 2004-09-09 11:55:43
请问如何用vb实现iis下网站访问身份验证方式的修改,想在网站自动安装时自动去掉匿名的访问方式,改成集成身份验证,请教用vb该如何实现?先谢谢了
...全文
100 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
// Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service.
var locatorObj = new ActiveXObject("WbemScripting.SWbemLocator");
var providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2");
var serviceObj = providerObj.Get("IIsWebService='W3SVC'");

// Build binding object, which is a required parameter of the CreateNewSite method.
// Use the SpawnInstance WMI method since we are creating a new instance of an object.
var Bindings = new Array();
Bindings[0] = providerObj.get("ServerBinding").SpawnInstance_();
Bindings[0].IP = "";
Bindings[0].Port = "8383";
Bindings[0].Hostname = "";

// Create the new Web site using the CreateNewSite method of the IIsWebService object.
try {
var strSiteObjPath;
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\\Inetpub\\Wwwroot");
}
catch(e) {
WScript.Echo("*** Error Creating Site: " + e + " " + e.Number + ", " + e.Description + " ***");
WScript.Quit(1);
}

// strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907'
// To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object.
var objPath = new ActiveXObject("WbemScripting.SWbemObjectPath");
objPath.Path = strSiteObjPath;
strSitePath = objPath.Keys.Item("");

// var some properties on the root virtual directory which was created by CreateNewSite.
var vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" + strSitePath + "/ROOT'");
vdirObj.AuthFlags = 5; // AuthNTLM + AuthAnonymous
vdirObj.EnableDefaultDoc = true;
vdirObj.DirBrowseFlags = 0x4000003E; // date, time, size, extension, longdate
vdirObj.AccessFlags = 513; // read, script
vdirObj.AppFriendlyName = "Root Application";

// Save the new settings to the metabase
vdirObj.Put_();

// CreateNewSite does not start the server, so start it now.
var serverObj = providerObj.Get(strSiteObjPath);
serverObj.Start;

WScript.Echo("A New site called MyNewSite was created with the path and unique site identification
  • 打赏
  • 举报
回复
偶晕………………
如题,现在已经可以建立虚拟站点和虚拟目录,但是删除站点和目录的时候报错,提示路径无法找到,创建的代码如下:
http://www.itraining.net.cn/lzh/showArticle.asp?art_ID=678
请大侠帮忙写出删除的代码,谢了!!!
---------------------------------------------------------------

up
---------------------------------------------------------------

帮你顶
---------------------------------------------------------------

see the example at

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=Ob59%23ZYdBHA.1488%40tkmsftngp02

---------------------------------------------------------------

发布虚拟站点
'参数:
' strWebSite 虚拟站点名称
' strFriendlyName 程序名称
' strWebPath 网页文件路径
' strDefaultDoc 默认网站首页

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 Function
=======================================

---------------------------------------------------------------

Up 关注ing...
---------------------------------------------------------------

我知道了,代码如下:
Function DeleteWebsite(ByVal IISPath As String) As Boolean
Dim DirObj
Dim ObjectParam As String
On Error GoTo errs
'IISpath格式为:IIS://机器名/W3SVC/虚拟站点号/ROOT/虚拟目录
If IISPath = "" Then Exit Function
DeleteWebsite = True
ObjectParam = SplitParam(IISPath)
If UCase(ObjectParam) = "ROOT" Then ObjectParam = SplitParam(IISPath) '如果是虚拟站点,那么IIS路径应该再退到上一层
Set DirObj = GetObject(IISPath)
DirObj.Delete "IIsObject", ObjectParam
Exit Function

errs:
If err.Number <> 462 Then
MsgBox "您的系统上可能没有安装IIS或IIS已经破坏!" & Chr(13) & Chr(10) & _
"错误号【" & err.Description & "】", vbOKOnly + vbExclamation, "系统错误"
DeleteWebsite = False
End If
End Function

Function SplitParam(ObjectPath)
' Note: Assume the string has been sanitized (no leading or trailing slashes)
On Error Resume Next

Dim SlashIndex
Dim TempParam
Dim ObjectPathLen

SplitParam = "" ' Assume no parameter
ObjectPathLen = Len(ObjectPath)

' Separate the path of the node from the parameter
SlashIndex = InStrRev(ObjectPath, "/")

If (SlashIndex = 0) Or (SlashIndex = ObjectPathLen) Then
TempParam = ObjectPath
ObjectPath = "" ' ObjectParameter is more important
Else
TempParam = ObjectPath
ObjectPath = Left(ObjectPath, SlashIndex - 1)
TempParam = Right(TempParam, Len(TempParam) - SlashIndex)
End If

SplitParam = TempParam

End Function

使用方法:DeleteWebsite(IIspath)
weiym 2004-09-09
  • 打赏
  • 举报
回复
问题已经解决
查了好多资料,其实只要一句话
ServerObj.AuthFlags = 2
今天心情好,明天结贴发分
starsoulxp 2004-09-09
  • 打赏
  • 举报
回复
可惜我不会啊,帮你up
caojinrong 2004-09-09
  • 打赏
  • 举报
回复
不会,顶一下先。
tztz520 2004-09-09
  • 打赏
  • 举报
回复
帮你顶.
weiym 2004-09-09
  • 打赏
  • 举报
回复
我顶,怎么没有人回答啊?

8,327

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 IIS
社区管理员
  • IIS
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧