17

## 計算Windows網域內電腦開機數量

10.66.21.5,0 ms,N/A,N/A
10.66.21.6,0 ms,N/A,N/A
10.66.21.7,0 ms,N/A,N/A

On error resume next
filename=mid(now,1,4)&mid(now,6,instrRev(now,"/")-instr(now,"/")-1)&mid(now,instrRev(now,"/")+1,instr(now," ")-instrRev(now,"/")-1)&mid

(now,instr(now," ")+1,2)&mid(now,instrRev(now," ")+1,2)&mid(now,instrRev(now," ")+4,2)&".xls"
ComputerCount=0
Set fso = CreateObject("Scripting.FileSystemObject")

strDomainDn="dc=xxx,dc=xxx"
'strDomainDn = InputBox("Enter the DN of your domain." & vbCrLf & "(i.e. dc=domain,dc=com)")網域名稱

objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://" & strDomainDn & "' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000

Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF

strComputer = objRecordSet.Fields("Name").Value
Set objShell = CreateObject("WScript.Shell")
strCommand = "%comspec% /c ping -n 3 -w 2000 " & strComputer & ""
Set objExecObject = objShell.Exec(strCommand)

Do While Not objExecObject.StdOut.AtEndOfStream
If Instr(strText, "bytes=32") > 0 Then
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_OperatingSystem")
Set colItems3 = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in ColItems
strOS = objItem.Caption
Next
For Each objItem in colitems3
Next
If Err.Number > 0 then
strErrorSystems = strComputer & ", " & strErrorSystems
Else
ComputerCount=ComputerCount+1
upgrade.Write strComputer & " 使用者帳號: " & strUserName & " 電腦IP: " & mid(strText,Instr(strText, "from")

+5,Instr(strText, "bytes=32")-Instr(strText, "from")-7) & " 作業系統: " & strOS &" 時間: "&now & vbCrLf
' End If
End If
'flushes error code from the previous loop
Err.Clear
Else
UnavailableSystems = strComputer & ", " & UnavailableSystems
End If
Loop
objRecordSet.MoveNext
Loop

### 10 則留言

0

iT邦高手 1 級 ‧ 2008-05-23 13:09:05

0
john651216
iT邦研究生 1 級 ‧ 2008-05-23 14:04:16

0
dyr0955
iT邦新手 3 級 ‧ 2008-05-23 14:39:47

0
hydrachen23
iT邦新手 1 級 ‧ 2008-05-23 17:26:24

0
jerry640
iT邦新手 1 級 ‧ 2008-05-24 02:30:33

0
fanylu60
iT邦研究生 1 級 ‧ 2008-05-24 09:31:18

0
yce701116
iT邦研究生 1 級 ‧ 2008-05-24 10:28:27

0
cutejohnny
iT邦新手 4 級 ‧ 2008-05-24 23:34:32

0
jamesallin
iT邦新手 4 級 ‧ 2008-05-29 13:11:49
0
mmm12345
iT邦研究生 1 級 ‧ 2008-06-01 10:34:23