更新代码:脚本执行但不输出任何内容,Excel.exe 进程继续运行。我需要将其输出到启动 .vbs 脚本的目录,并将 Excel 文件命名为 Book1.xls 以外的其他名称
Option Explicit
Dim strFile, strGroupDN, objGroup, objExcel, intRow, objMember, objSheet
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain, strGroup
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
strNetBIOSDomain = Left(strNetBIOSDomain, _
Len(strNetBIOSDomain) - 1)
strGroup = InputBox("Enter AD group name")
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strGroup
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Group " & strGroup & " not found"
Wscript.Quit
End If
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
Set objGroup = GetObject("LDAP://" & strGroupDN)
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
objExcel.Columns(1).ColumnWidth = 100
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "AD Group Members"
intRow = 1
For Each objMember In objGroup.Members
objSheet.Cells(intRow, 1).Value = objMember.sAMAccountName
intRow = intRow + 1
Next
Set fso = CreateObject("Scripting.FileSystemObject")
cwd = fso.GetAbsolutePathName("*.*")
filename = fso.BuildPath(cwd, "output.xls")
objExcel.ActiveWorkbook.SaveAs filename