更新的代碼:該腳本執行但不輸出任何內容,Excel.exe進程繼續運行。我想這能輸出到.vbs腳本從啓動目錄並將其命名爲Excel文件以外的東西比Book1.xls的Excel VBS將輸出保存到腳本從
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
我改變了代碼,但它仍然提示我保存並強制我選擇一個位置。在這個例子中,我從桌面啓動.vbs。 – DWard